authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-18 10:51:08+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-18 11:39:52+03:00
log4f02cf32b43d725ebad8331cd0967b47597b29de
treed3183ea2d413966ebfd8b756d2517b95baf8c759
parent1afaf42525760edb78c287c216fda4aafc03d68f
signature Commit is signed but in an unrecognized format.

fix typeInfo tests


3 files changed, 39 insertions(+), 51 deletions(-)

src/ir.cpp+6-7
...@@ -27910,11 +27910,10 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro...@@ -27910,11 +27910,10 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2791027910
27911 if (cc == CallingConventionC) {27911 if (cc == CallingConventionC) {
27912 break;27912 break;
27913 } else if (cc == CallingConventionUnspecified) {
27914 lazy_fn_type->is_generic = true;
27915 return result;
27916 } else {27913 } else {
27917 zig_unreachable();27914 ir_add_error(ira, &instruction->base.base,
27915 buf_sprintf("var args only allowed in functions with C calling convention"));
27916 return ira->codegen->invalid_inst_gen;
27918 }27917 }
27919 }27918 }
2792027919
...@@ -30979,10 +30978,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -30979,10 +30978,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
30979 if (fn_type_id.cc == CallingConventionC) {30978 if (fn_type_id.cc == CallingConventionC) {
30980 fn_type_id.param_count = fn_type_id.next_param_index;30979 fn_type_id.param_count = fn_type_id.next_param_index;
30981 break;30980 break;
30982 } else if (fn_type_id.cc == CallingConventionUnspecified) {
30983 return get_generic_fn_type(ira->codegen, &fn_type_id);
30984 } else {30981 } else {
30985 zig_unreachable();30982 ir_add_error_node(ira, param_node,
30983 buf_sprintf("var args only allowed in functions with C calling convention"));
30984 return nullptr;
30986 }30985 }
30987 }30986 }
30988 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];30987 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
test/compile_errors.zig-9
...@@ -712,15 +712,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -712,15 +712,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
712 "tmp.zig:2:28: error: invalid character: ';'",712 "tmp.zig:2:28: error: invalid character: ';'",
713 });713 });
714714
715 cases.add("var args without c calling conv",
716 \\fn foo(args: ...) void {}
717 \\comptime {
718 \\ _ = foo;
719 \\}
720 , &[_][]const u8{
721 "tmp.zig:1:8: error: var args only allowed in functions with C calling convention",
722 });
723
724 cases.add("comptime struct field, no init value",715 cases.add("comptime struct field, no init value",
725 \\const Foo = struct {716 \\const Foo = struct {
726 \\ comptime b: i32,717 \\ comptime b: i32,
test/stage1/behavior/type_info.zig+33-35
...@@ -13,7 +13,7 @@ test "type info: tag type, void info" {...@@ -13,7 +13,7 @@ test "type info: tag type, void info" {
13fn testBasic() void {13fn testBasic() void {
14 expect(@TagType(TypeInfo) == TypeId);14 expect(@TagType(TypeInfo) == TypeId);
15 const void_info = @typeInfo(void);15 const void_info = @typeInfo(void);
16 expect(@as(TypeId, void_info) == TypeId.Void);16 expect(void_info == TypeId.Void);
17 expect(void_info.Void == {});17 expect(void_info.Void == {});
18}18}
1919
...@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {...@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {
2424
25fn testIntFloat() void {25fn testIntFloat() void {
26 const u8_info = @typeInfo(u8);26 const u8_info = @typeInfo(u8);
27 expect(@as(TypeId, u8_info) == TypeId.Int);27 expect(u8_info == .Int);
28 expect(!u8_info.Int.is_signed);28 expect(!u8_info.Int.is_signed);
29 expect(u8_info.Int.bits == 8);29 expect(u8_info.Int.bits == 8);
3030
31 const f64_info = @typeInfo(f64);31 const f64_info = @typeInfo(f64);
32 expect(@as(TypeId, f64_info) == TypeId.Float);32 expect(f64_info == .Float);
33 expect(f64_info.Float.bits == 64);33 expect(f64_info.Float.bits == 64);
34}34}
3535
...@@ -40,7 +40,7 @@ test "type info: pointer type info" {...@@ -40,7 +40,7 @@ test "type info: pointer type info" {
4040
41fn testPointer() void {41fn testPointer() void {
42 const u32_ptr_info = @typeInfo(*u32);42 const u32_ptr_info = @typeInfo(*u32);
43 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);43 expect(u32_ptr_info == .Pointer);
44 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);44 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
45 expect(u32_ptr_info.Pointer.is_const == false);45 expect(u32_ptr_info.Pointer.is_const == false);
46 expect(u32_ptr_info.Pointer.is_volatile == false);46 expect(u32_ptr_info.Pointer.is_volatile == false);
...@@ -56,7 +56,7 @@ test "type info: unknown length pointer type info" {...@@ -56,7 +56,7 @@ test "type info: unknown length pointer type info" {
5656
57fn testUnknownLenPtr() void {57fn testUnknownLenPtr() void {
58 const u32_ptr_info = @typeInfo([*]const volatile f64);58 const u32_ptr_info = @typeInfo([*]const volatile f64);
59 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);59 expect(u32_ptr_info == .Pointer);
60 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);60 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
61 expect(u32_ptr_info.Pointer.is_const == true);61 expect(u32_ptr_info.Pointer.is_const == true);
62 expect(u32_ptr_info.Pointer.is_volatile == true);62 expect(u32_ptr_info.Pointer.is_volatile == true);
...@@ -72,7 +72,7 @@ test "type info: null terminated pointer type info" {...@@ -72,7 +72,7 @@ test "type info: null terminated pointer type info" {
7272
73fn testNullTerminatedPtr() void {73fn testNullTerminatedPtr() void {
74 const ptr_info = @typeInfo([*:0]u8);74 const ptr_info = @typeInfo([*:0]u8);
75 expect(@as(TypeId, ptr_info) == TypeId.Pointer);75 expect(ptr_info == .Pointer);
76 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);76 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
77 expect(ptr_info.Pointer.is_const == false);77 expect(ptr_info.Pointer.is_const == false);
78 expect(ptr_info.Pointer.is_volatile == false);78 expect(ptr_info.Pointer.is_volatile == false);
...@@ -91,8 +91,8 @@ test "type info: C pointer type info" {...@@ -91,8 +91,8 @@ test "type info: C pointer type info" {
9191
92fn testCPtr() void {92fn testCPtr() void {
93 const ptr_info = @typeInfo([*c]align(4) const i8);93 const ptr_info = @typeInfo([*c]align(4) const i8);
94 expect(@as(TypeId, ptr_info) == TypeId.Pointer);94 expect(ptr_info == .Pointer);
95 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);95 expect(ptr_info.Pointer.size == .C);
96 expect(ptr_info.Pointer.is_const);96 expect(ptr_info.Pointer.is_const);
97 expect(!ptr_info.Pointer.is_volatile);97 expect(!ptr_info.Pointer.is_volatile);
98 expect(ptr_info.Pointer.alignment == 4);98 expect(ptr_info.Pointer.alignment == 4);
...@@ -106,8 +106,8 @@ test "type info: slice type info" {...@@ -106,8 +106,8 @@ test "type info: slice type info" {
106106
107fn testSlice() void {107fn testSlice() void {
108 const u32_slice_info = @typeInfo([]u32);108 const u32_slice_info = @typeInfo([]u32);
109 expect(@as(TypeId, u32_slice_info) == TypeId.Pointer);109 expect(u32_slice_info == .Pointer);
110 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);110 expect(u32_slice_info.Pointer.size == .Slice);
111 expect(u32_slice_info.Pointer.is_const == false);111 expect(u32_slice_info.Pointer.is_const == false);
112 expect(u32_slice_info.Pointer.is_volatile == false);112 expect(u32_slice_info.Pointer.is_volatile == false);
113 expect(u32_slice_info.Pointer.alignment == 4);113 expect(u32_slice_info.Pointer.alignment == 4);
...@@ -121,7 +121,7 @@ test "type info: array type info" {...@@ -121,7 +121,7 @@ test "type info: array type info" {
121121
122fn testArray() void {122fn testArray() void {
123 const arr_info = @typeInfo([42]bool);123 const arr_info = @typeInfo([42]bool);
124 expect(@as(TypeId, arr_info) == TypeId.Array);124 expect(arr_info == .Array);
125 expect(arr_info.Array.len == 42);125 expect(arr_info.Array.len == 42);
126 expect(arr_info.Array.child == bool);126 expect(arr_info.Array.child == bool);
127}127}
...@@ -133,7 +133,7 @@ test "type info: optional type info" {...@@ -133,7 +133,7 @@ test "type info: optional type info" {
133133
134fn testOptional() void {134fn testOptional() void {
135 const null_info = @typeInfo(?void);135 const null_info = @typeInfo(?void);
136 expect(@as(TypeId, null_info) == TypeId.Optional);136 expect(null_info == .Optional);
137 expect(null_info.Optional.child == void);137 expect(null_info.Optional.child == void);
138}138}
139139
...@@ -150,18 +150,18 @@ fn testErrorSet() void {...@@ -150,18 +150,18 @@ fn testErrorSet() void {
150 };150 };
151151
152 const error_set_info = @typeInfo(TestErrorSet);152 const error_set_info = @typeInfo(TestErrorSet);
153 expect(@as(TypeId, error_set_info) == TypeId.ErrorSet);153 expect(error_set_info == .ErrorSet);
154 expect(error_set_info.ErrorSet.?.len == 3);154 expect(error_set_info.ErrorSet.?.len == 3);
155 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));155 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
156 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));156 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));
157157
158 const error_union_info = @typeInfo(TestErrorSet!usize);158 const error_union_info = @typeInfo(TestErrorSet!usize);
159 expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion);159 expect(error_union_info == .ErrorUnion);
160 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);160 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
161 expect(error_union_info.ErrorUnion.payload == usize);161 expect(error_union_info.ErrorUnion.payload == usize);
162162
163 const global_info = @typeInfo(anyerror);163 const global_info = @typeInfo(anyerror);
164 expect(@as(TypeId, global_info) == TypeId.ErrorSet);164 expect(global_info == .ErrorSet);
165 expect(global_info.ErrorSet == null);165 expect(global_info.ErrorSet == null);
166}166}
167167
...@@ -179,8 +179,8 @@ fn testEnum() void {...@@ -179,8 +179,8 @@ fn testEnum() void {
179 };179 };
180180
181 const os_info = @typeInfo(Os);181 const os_info = @typeInfo(Os);
182 expect(@as(TypeId, os_info) == TypeId.Enum);182 expect(os_info == .Enum);
183 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);183 expect(os_info.Enum.layout == .Auto);
184 expect(os_info.Enum.fields.len == 4);184 expect(os_info.Enum.fields.len == 4);
185 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));185 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
186 expect(os_info.Enum.fields[3].value == 3);186 expect(os_info.Enum.fields[3].value == 3);
...@@ -195,8 +195,8 @@ test "type info: union info" {...@@ -195,8 +195,8 @@ test "type info: union info" {
195195
196fn testUnion() void {196fn testUnion() void {
197 const typeinfo_info = @typeInfo(TypeInfo);197 const typeinfo_info = @typeInfo(TypeInfo);
198 expect(@as(TypeId, typeinfo_info) == TypeId.Union);198 expect(typeinfo_info == .Union);
199 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);199 expect(typeinfo_info.Union.layout == .Auto);
200 expect(typeinfo_info.Union.tag_type.? == TypeId);200 expect(typeinfo_info.Union.tag_type.? == TypeId);
201 expect(typeinfo_info.Union.fields.len == 25);201 expect(typeinfo_info.Union.fields.len == 25);
202 expect(typeinfo_info.Union.fields[4].enum_field != null);202 expect(typeinfo_info.Union.fields[4].enum_field != null);
...@@ -210,9 +210,9 @@ fn testUnion() void {...@@ -210,9 +210,9 @@ fn testUnion() void {
210 };210 };
211211
212 const notag_union_info = @typeInfo(TestNoTagUnion);212 const notag_union_info = @typeInfo(TestNoTagUnion);
213 expect(@as(TypeId, notag_union_info) == TypeId.Union);213 expect(notag_union_info == .Union);
214 expect(notag_union_info.Union.tag_type == null);214 expect(notag_union_info.Union.tag_type == null);
215 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);215 expect(notag_union_info.Union.layout == .Auto);
216 expect(notag_union_info.Union.fields.len == 2);216 expect(notag_union_info.Union.fields.len == 2);
217 expect(notag_union_info.Union.fields[0].enum_field == null);217 expect(notag_union_info.Union.fields[0].enum_field == null);
218 expect(notag_union_info.Union.fields[1].field_type == u32);218 expect(notag_union_info.Union.fields[1].field_type == u32);
...@@ -222,7 +222,7 @@ fn testUnion() void {...@@ -222,7 +222,7 @@ fn testUnion() void {
222 };222 };
223223
224 const extern_union_info = @typeInfo(TestExternUnion);224 const extern_union_info = @typeInfo(TestExternUnion);
225 expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);225 expect(extern_union_info.Union.layout == .Extern);
226 expect(extern_union_info.Union.tag_type == null);226 expect(extern_union_info.Union.tag_type == null);
227 expect(extern_union_info.Union.fields[0].enum_field == null);227 expect(extern_union_info.Union.fields[0].enum_field == null);
228 expect(extern_union_info.Union.fields[0].field_type == *c_void);228 expect(extern_union_info.Union.fields[0].field_type == *c_void);
...@@ -235,8 +235,8 @@ test "type info: struct info" {...@@ -235,8 +235,8 @@ test "type info: struct info" {
235235
236fn testStruct() void {236fn testStruct() void {
237 const struct_info = @typeInfo(TestStruct);237 const struct_info = @typeInfo(TestStruct);
238 expect(@as(TypeId, struct_info) == TypeId.Struct);238 expect(struct_info == .Struct);
239 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);239 expect(struct_info.Struct.layout == .Packed);
240 expect(struct_info.Struct.fields.len == 4);240 expect(struct_info.Struct.fields.len == 4);
241 expect(struct_info.Struct.fields[1].offset == null);241 expect(struct_info.Struct.fields[1].offset == null);
242 expect(struct_info.Struct.fields[2].field_type == *TestStruct);242 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
...@@ -268,22 +268,20 @@ test "type info: function type info" {...@@ -268,22 +268,20 @@ test "type info: function type info" {
268268
269fn testFunction() void {269fn testFunction() void {
270 const fn_info = @typeInfo(@TypeOf(foo));270 const fn_info = @typeInfo(@TypeOf(foo));
271 expect(@as(TypeId, fn_info) == TypeId.Fn);271 expect(fn_info == .Fn);
272 expect(fn_info.Fn.calling_convention == .Unspecified);272 expect(fn_info.Fn.calling_convention == .C);
273 expect(fn_info.Fn.is_generic);273 expect(!fn_info.Fn.is_generic);
274 expect(fn_info.Fn.args.len == 2);274 expect(fn_info.Fn.args.len == 2);
275 expect(fn_info.Fn.is_var_args);275 expect(fn_info.Fn.is_var_args);
276 expect(fn_info.Fn.return_type == null);276 expect(fn_info.Fn.return_type.? == usize);
277277
278 const test_instance: TestStruct = undefined;278 const test_instance: TestStruct = undefined;
279 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));279 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
280 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);280 expect(bound_fn_info == .BoundFn);
281 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);281 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
282}282}
283283
284fn foo(comptime a: usize, b: bool, args: ...) usize {284extern fn foo(a: usize, b: bool, args: ...) usize;
285 return 0;
286}
287285
288test "typeInfo with comptime parameter in struct fn def" {286test "typeInfo with comptime parameter in struct fn def" {
289 const S = struct {287 const S = struct {
...@@ -299,7 +297,7 @@ test "type info: vectors" {...@@ -299,7 +297,7 @@ test "type info: vectors" {
299297
300fn testVector() void {298fn testVector() void {
301 const vec_info = @typeInfo(@Vector(4, i32));299 const vec_info = @typeInfo(@Vector(4, i32));
302 expect(@as(TypeId, vec_info) == TypeId.Vector);300 expect(vec_info == .Vector);
303 expect(vec_info.Vector.len == 4);301 expect(vec_info.Vector.len == 4);
304 expect(vec_info.Vector.child == i32);302 expect(vec_info.Vector.child == i32);
305}303}
...@@ -312,13 +310,13 @@ test "type info: anyframe and anyframe->T" {...@@ -312,13 +310,13 @@ test "type info: anyframe and anyframe->T" {
312fn testAnyFrame() void {310fn testAnyFrame() void {
313 {311 {
314 const anyframe_info = @typeInfo(anyframe->i32);312 const anyframe_info = @typeInfo(anyframe->i32);
315 expect(@as(TypeId, anyframe_info) == .AnyFrame);313 expect(anyframe_info == .AnyFrame);
316 expect(anyframe_info.AnyFrame.child.? == i32);314 expect(anyframe_info.AnyFrame.child.? == i32);
317 }315 }
318316
319 {317 {
320 const anyframe_info = @typeInfo(anyframe);318 const anyframe_info = @typeInfo(anyframe);
321 expect(@as(TypeId, anyframe_info) == .AnyFrame);319 expect(anyframe_info == .AnyFrame);
322 expect(anyframe_info.AnyFrame.child == null);320 expect(anyframe_info.AnyFrame.child == null);
323 }321 }
324}322}