| author | |
| committer | |
| log | 2b40815a220bbbd657bfa441e304090f11f1eb4c |
| tree | 01ba879103b9f49d58ea90a3244933c58dc34be2 |
| parent | f28868e8fd4028cad29bd2de8c0aa1c1713c69dd |
In the case of a comptime function call of a function that returns a
type, resulting in a compiler crash on deinit().4 files changed, 27 insertions(+), 24 deletions(-)
src/Module.zig-1| ... | @@ -4037,7 +4037,6 @@ pub fn createAnonymousDeclFromDeclNamed( | ... | @@ -4037,7 +4037,6 @@ pub fn createAnonymousDeclFromDeclNamed( |
| 4037 | new_decl.ty = typed_value.ty; | 4037 | new_decl.ty = typed_value.ty; |
| 4038 | new_decl.val = typed_value.val; | 4038 | new_decl.val = typed_value.val; |
| 4039 | new_decl.has_tv = true; | 4039 | new_decl.has_tv = true; |
| 4040 | new_decl.owns_tv = true; | ||
| 4041 | new_decl.analysis = .complete; | 4040 | new_decl.analysis = .complete; |
| 4042 | new_decl.generation = mod.generation; | 4041 | new_decl.generation = mod.generation; |
| 4043 | 4042 |
src/Sema.zig+4| ... | @@ -866,6 +866,7 @@ fn zirStructDecl( | ... | @@ -866,6 +866,7 @@ fn zirStructDecl( |
| 866 | .ty = Type.initTag(.type), | 866 | .ty = Type.initTag(.type), |
| 867 | .val = struct_val, | 867 | .val = struct_val, |
| 868 | }, type_name); | 868 | }, type_name); |
| 869 | new_decl.owns_tv = true; | ||
| 869 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 870 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 870 | struct_obj.* = .{ | 871 | struct_obj.* = .{ |
| 871 | .owner_decl = new_decl, | 872 | .owner_decl = new_decl, |
| ... | @@ -986,6 +987,7 @@ fn zirEnumDecl( | ... | @@ -986,6 +987,7 @@ fn zirEnumDecl( |
| 986 | .ty = Type.initTag(.type), | 987 | .ty = Type.initTag(.type), |
| 987 | .val = enum_val, | 988 | .val = enum_val, |
| 988 | }, type_name); | 989 | }, type_name); |
| 990 | new_decl.owns_tv = true; | ||
| 989 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 991 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 990 | 992 | ||
| 991 | enum_obj.* = .{ | 993 | enum_obj.* = .{ |
| ... | @@ -1152,6 +1154,7 @@ fn zirUnionDecl( | ... | @@ -1152,6 +1154,7 @@ fn zirUnionDecl( |
| 1152 | .ty = Type.initTag(.type), | 1154 | .ty = Type.initTag(.type), |
| 1153 | .val = union_val, | 1155 | .val = union_val, |
| 1154 | }, type_name); | 1156 | }, type_name); |
| 1157 | new_decl.owns_tv = true; | ||
| 1155 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1158 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1156 | union_obj.* = .{ | 1159 | union_obj.* = .{ |
| 1157 | .owner_decl = new_decl, | 1160 | .owner_decl = new_decl, |
| ... | @@ -1223,6 +1226,7 @@ fn zirErrorSetDecl( | ... | @@ -1223,6 +1226,7 @@ fn zirErrorSetDecl( |
| 1223 | .ty = Type.initTag(.type), | 1226 | .ty = Type.initTag(.type), |
| 1224 | .val = error_set_val, | 1227 | .val = error_set_val, |
| 1225 | }, type_name); | 1228 | }, type_name); |
| 1229 | new_decl.owns_tv = true; | ||
| 1226 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); | 1230 | errdefer sema.mod.deleteAnonDecl(&block.base, new_decl); |
| 1227 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); | 1231 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); |
| 1228 | for (fields) |str_index, i| { | 1232 | for (fields) |str_index, i| { |
test/behavior/generics.zig+23-2| ... | @@ -80,7 +80,7 @@ fn max_f64(a: f64, b: f64) f64 { | ... | @@ -80,7 +80,7 @@ fn max_f64(a: f64, b: f64) f64 { |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | test "type constructed by comptime function call" { | 82 | test "type constructed by comptime function call" { |
| 83 | var l: List(10) = undefined; | 83 | var l: SimpleList(10) = undefined; |
| 84 | l.array[0] = 10; | 84 | l.array[0] = 10; |
| 85 | l.array[1] = 11; | 85 | l.array[1] = 11; |
| 86 | l.array[2] = 12; | 86 | l.array[2] = 12; |
| ... | @@ -90,9 +90,30 @@ test "type constructed by comptime function call" { | ... | @@ -90,9 +90,30 @@ test "type constructed by comptime function call" { |
| 90 | try expect(ptr[2] == 12); | 90 | try expect(ptr[2] == 12); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | fn List(comptime L: usize) type { | 93 | fn SimpleList(comptime L: usize) type { |
| 94 | var T = u8; | 94 | var T = u8; |
| 95 | return struct { | 95 | return struct { |
| 96 | array: [L]T, | 96 | array: [L]T, |
| 97 | }; | 97 | }; |
| 98 | } | 98 | } |
| 99 | |||
| 100 | test "function with return type type" { | ||
| 101 | var list: List(i32) = undefined; | ||
| 102 | var list2: List(i32) = undefined; | ||
| 103 | list.length = 10; | ||
| 104 | list2.length = 10; | ||
| 105 | try expect(list.prealloc_items.len == 8); | ||
| 106 | try expect(list2.prealloc_items.len == 8); | ||
| 107 | } | ||
| 108 | |||
| 109 | pub fn List(comptime T: type) type { | ||
| 110 | return SmallList(T, 8); | ||
| 111 | } | ||
| 112 | |||
| 113 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { | ||
| 114 | return struct { | ||
| 115 | items: []T, | ||
| 116 | length: usize, | ||
| 117 | prealloc_items: [STATIC_SIZE]T, | ||
| 118 | }; | ||
| 119 | } |
test/behavior/generics_stage1.zig-21| ... | @@ -3,27 +3,6 @@ const testing = std.testing; | ... | @@ -3,27 +3,6 @@ const testing = std.testing; |
| 3 | const expect = testing.expect; | 3 | const expect = testing.expect; |
| 4 | const expectEqual = testing.expectEqual; | 4 | const expectEqual = testing.expectEqual; |
| 5 | 5 | ||
| 6 | pub fn List(comptime T: type) type { | ||
| 7 | return SmallList(T, 8); | ||
| 8 | } | ||
| 9 | |||
| 10 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { | ||
| 11 | return struct { | ||
| 12 | items: []T, | ||
| 13 | length: usize, | ||
| 14 | prealloc_items: [STATIC_SIZE]T, | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | test "function with return type type" { | ||
| 19 | var list: List(i32) = undefined; | ||
| 20 | var list2: List(i32) = undefined; | ||
| 21 | list.length = 10; | ||
| 22 | list2.length = 10; | ||
| 23 | try expect(list.prealloc_items.len == 8); | ||
| 24 | try expect(list2.prealloc_items.len == 8); | ||
| 25 | } | ||
| 26 | |||
| 27 | test "generic struct" { | 6 | test "generic struct" { |
| 28 | var a1 = GenNode(i32){ | 7 | var a1 = GenNode(i32){ |
| 29 | .value = 13, | 8 | .value = 13, |