authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-18 14:35:35-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-04-18 14:35:35-04:00
log6b2274fd994edfd26db49d4a2599bbace881fd7a
tree843bf548308728f53752b04c1219ea2949b1d2a4
parent344f4d9bc586507c00324cd3844b9b9f778a3c65
parent4f02cf32b43d725ebad8331cd0967b47597b29de
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #5088 from Vexu/varargs-fix

Add error for non-exter variadic functions

4 files changed, 59 insertions(+), 56 deletions(-)

src/analyze.cpp+7-1
...@@ -3619,12 +3619,18 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {...@@ -3619,12 +3619,18 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3619 assert(tld->source_node->type == NodeTypeFnProto);3619 assert(tld->source_node->type == NodeTypeFnProto);
3620 is_export = tld->source_node->data.fn_proto.is_export;3620 is_export = tld->source_node->data.fn_proto.is_export;
36213621
3622 if (!is_export && !tld->source_node->data.fn_proto.is_extern &&3622 if (!tld->source_node->data.fn_proto.is_extern &&
3623 tld->source_node->data.fn_proto.fn_def_node == nullptr)3623 tld->source_node->data.fn_proto.fn_def_node == nullptr)
3624 {3624 {
3625 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));3625 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
3626 return;3626 return;
3627 }3627 }
3628 if (!tld->source_node->data.fn_proto.is_extern &&
3629 tld->source_node->data.fn_proto.is_var_args)
3630 {
3631 add_node_error(g, tld->source_node, buf_sprintf("non-extern function is variadic"));
3632 return;
3633 }
3628 } else if (tld->id == TldIdUsingNamespace) {3634 } else if (tld->id == TldIdUsingNamespace) {
3629 g->resolve_queue.append(tld);3635 g->resolve_queue.append(tld);
3630 }3636 }
src/ir.cpp+7-8
...@@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
25375 case ZigTypeIdBoundFn:25375 case ZigTypeIdBoundFn:
25376 case ZigTypeIdStruct:25376 case ZigTypeIdStruct:
25377 ir_add_error(ira, source_instr, buf_sprintf(25377 ir_add_error(ira, source_instr, buf_sprintf(
25378 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));25378 "@Type not available for 'TypeInfo.%s'", type_id_name(tagTypeId)));
25379 return ira->codegen->invalid_inst_gen->value->type;25379 return ira->codegen->invalid_inst_gen->value->type;
25380 }25380 }
25381 zig_unreachable();25381 zig_unreachable();
...@@ -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+12-12
...@@ -2,6 +2,15 @@ const tests = @import("tests.zig");...@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
2const std = @import("std");2const std = @import("std");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("non-extern function with var args",
6 \\fn foo(args: ...) void {}
7 \\export fn entry() void {
8 \\ foo();
9 \\}
10 , &[_][]const u8{
11 "tmp.zig:1:1: error: non-extern function is variadic",
12 });
13
5 cases.addTest("invalid int casts",14 cases.addTest("invalid int casts",
6 \\export fn foo() void {15 \\export fn foo() void {
7 \\ var a: u32 = 2;16 \\ var a: u32 = 2;
...@@ -703,15 +712,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -703,15 +712,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
703 "tmp.zig:2:28: error: invalid character: ';'",712 "tmp.zig:2:28: error: invalid character: ';'",
704 });713 });
705714
706 cases.add("var args without c calling conv",
707 \\fn foo(args: ...) void {}
708 \\comptime {
709 \\ _ = foo;
710 \\}
711 , &[_][]const u8{
712 "tmp.zig:1:8: error: var args only allowed in functions with C calling convention",
713 });
714
715 cases.add("comptime struct field, no init value",715 cases.add("comptime struct field, no init value",
716 \\const Foo = struct {716 \\const Foo = struct {
717 \\ comptime b: i32,717 \\ comptime b: i32,
...@@ -856,7 +856,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -856,7 +856,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
856 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",856 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
857 });857 });
858858
859 cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",859 cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional",
860 \\fn maybe(is: bool) ?u8 {860 \\fn maybe(is: bool) ?u8 {
861 \\ if (is) return @as(u8, 10) else return null;861 \\ if (is) return @as(u8, 10) else return null;
862 \\}862 \\}
...@@ -1084,7 +1084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1084,7 +1084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1084 \\ _ = @Type(@typeInfo(struct { }));1084 \\ _ = @Type(@typeInfo(struct { }));
1085 \\}1085 \\}
1086 , &[_][]const u8{1086 , &[_][]const u8{
1087 "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",1087 "tmp.zig:2:15: error: @Type not available for 'TypeInfo.Struct'",
1088 });1088 });
10891089
1090 cases.add("wrong type for result ptr to @asyncCall",1090 cases.add("wrong type for result ptr to @asyncCall",
...@@ -2659,7 +2659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2659,7 +2659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2659 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",2659 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
2660 });2660 });
26612661
2662 cases.add("function protoype with no body",2662 cases.add("function prototype with no body",
2663 \\fn foo() void;2663 \\fn foo() void;
2664 \\export fn entry() void {2664 \\export fn entry() void {
2665 \\ foo();2665 \\ foo();
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}