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
2791027910
2791127911 if (cc == CallingConventionC) {
2791227912 break;
27913 } else if (cc == CallingConventionUnspecified) {
27914 lazy_fn_type->is_generic = true;
27915 return result;
2791627913 } 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;
2791827917 }
2791927918 }
2792027919
......@@ -30979,10 +30978,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
3097930978 if (fn_type_id.cc == CallingConventionC) {
3098030979 fn_type_id.param_count = fn_type_id.next_param_index;
3098130980 break;
30982 } else if (fn_type_id.cc == CallingConventionUnspecified) {
30983 return get_generic_fn_type(ira->codegen, &fn_type_id);
3098430981 } 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;
3098630985 }
3098730986 }
3098830987 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 {
712712 "tmp.zig:2:28: error: invalid character: ';'",
713713 });
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
724715 cases.add("comptime struct field, no init value",
725716 \\const Foo = struct {
726717 \\ comptime b: i32,
test/stage1/behavior/type_info.zig+33-35
......@@ -13,7 +13,7 @@ test "type info: tag type, void info" {
1313fn testBasic() void {
1414 expect(@TagType(TypeInfo) == TypeId);
1515 const void_info = @typeInfo(void);
16 expect(@as(TypeId, void_info) == TypeId.Void);
16 expect(void_info == TypeId.Void);
1717 expect(void_info.Void == {});
1818}
1919
......@@ -24,12 +24,12 @@ test "type info: integer, floating point type info" {
2424
2525fn testIntFloat() void {
2626 const u8_info = @typeInfo(u8);
27 expect(@as(TypeId, u8_info) == TypeId.Int);
27 expect(u8_info == .Int);
2828 expect(!u8_info.Int.is_signed);
2929 expect(u8_info.Int.bits == 8);
3030
3131 const f64_info = @typeInfo(f64);
32 expect(@as(TypeId, f64_info) == TypeId.Float);
32 expect(f64_info == .Float);
3333 expect(f64_info.Float.bits == 64);
3434}
3535
......@@ -40,7 +40,7 @@ test "type info: pointer type info" {
4040
4141fn testPointer() void {
4242 const u32_ptr_info = @typeInfo(*u32);
43 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);
43 expect(u32_ptr_info == .Pointer);
4444 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
4545 expect(u32_ptr_info.Pointer.is_const == false);
4646 expect(u32_ptr_info.Pointer.is_volatile == false);
......@@ -56,7 +56,7 @@ test "type info: unknown length pointer type info" {
5656
5757fn testUnknownLenPtr() void {
5858 const u32_ptr_info = @typeInfo([*]const volatile f64);
59 expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer);
59 expect(u32_ptr_info == .Pointer);
6060 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
6161 expect(u32_ptr_info.Pointer.is_const == true);
6262 expect(u32_ptr_info.Pointer.is_volatile == true);
......@@ -72,7 +72,7 @@ test "type info: null terminated pointer type info" {
7272
7373fn testNullTerminatedPtr() void {
7474 const ptr_info = @typeInfo([*:0]u8);
75 expect(@as(TypeId, ptr_info) == TypeId.Pointer);
75 expect(ptr_info == .Pointer);
7676 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
7777 expect(ptr_info.Pointer.is_const == false);
7878 expect(ptr_info.Pointer.is_volatile == false);
......@@ -91,8 +91,8 @@ test "type info: C pointer type info" {
9191
9292fn testCPtr() void {
9393 const ptr_info = @typeInfo([*c]align(4) const i8);
94 expect(@as(TypeId, ptr_info) == TypeId.Pointer);
95 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
94 expect(ptr_info == .Pointer);
95 expect(ptr_info.Pointer.size == .C);
9696 expect(ptr_info.Pointer.is_const);
9797 expect(!ptr_info.Pointer.is_volatile);
9898 expect(ptr_info.Pointer.alignment == 4);
......@@ -106,8 +106,8 @@ test "type info: slice type info" {
106106
107107fn testSlice() void {
108108 const u32_slice_info = @typeInfo([]u32);
109 expect(@as(TypeId, u32_slice_info) == TypeId.Pointer);
110 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
109 expect(u32_slice_info == .Pointer);
110 expect(u32_slice_info.Pointer.size == .Slice);
111111 expect(u32_slice_info.Pointer.is_const == false);
112112 expect(u32_slice_info.Pointer.is_volatile == false);
113113 expect(u32_slice_info.Pointer.alignment == 4);
......@@ -121,7 +121,7 @@ test "type info: array type info" {
121121
122122fn testArray() void {
123123 const arr_info = @typeInfo([42]bool);
124 expect(@as(TypeId, arr_info) == TypeId.Array);
124 expect(arr_info == .Array);
125125 expect(arr_info.Array.len == 42);
126126 expect(arr_info.Array.child == bool);
127127}
......@@ -133,7 +133,7 @@ test "type info: optional type info" {
133133
134134fn testOptional() void {
135135 const null_info = @typeInfo(?void);
136 expect(@as(TypeId, null_info) == TypeId.Optional);
136 expect(null_info == .Optional);
137137 expect(null_info.Optional.child == void);
138138}
139139
......@@ -150,18 +150,18 @@ fn testErrorSet() void {
150150 };
151151
152152 const error_set_info = @typeInfo(TestErrorSet);
153 expect(@as(TypeId, error_set_info) == TypeId.ErrorSet);
153 expect(error_set_info == .ErrorSet);
154154 expect(error_set_info.ErrorSet.?.len == 3);
155155 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
156156 expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third));
157157
158158 const error_union_info = @typeInfo(TestErrorSet!usize);
159 expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion);
159 expect(error_union_info == .ErrorUnion);
160160 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
161161 expect(error_union_info.ErrorUnion.payload == usize);
162162
163163 const global_info = @typeInfo(anyerror);
164 expect(@as(TypeId, global_info) == TypeId.ErrorSet);
164 expect(global_info == .ErrorSet);
165165 expect(global_info.ErrorSet == null);
166166}
167167
......@@ -179,8 +179,8 @@ fn testEnum() void {
179179 };
180180
181181 const os_info = @typeInfo(Os);
182 expect(@as(TypeId, os_info) == TypeId.Enum);
183 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
182 expect(os_info == .Enum);
183 expect(os_info.Enum.layout == .Auto);
184184 expect(os_info.Enum.fields.len == 4);
185185 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
186186 expect(os_info.Enum.fields[3].value == 3);
......@@ -195,8 +195,8 @@ test "type info: union info" {
195195
196196fn testUnion() void {
197197 const typeinfo_info = @typeInfo(TypeInfo);
198 expect(@as(TypeId, typeinfo_info) == TypeId.Union);
199 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
198 expect(typeinfo_info == .Union);
199 expect(typeinfo_info.Union.layout == .Auto);
200200 expect(typeinfo_info.Union.tag_type.? == TypeId);
201201 expect(typeinfo_info.Union.fields.len == 25);
202202 expect(typeinfo_info.Union.fields[4].enum_field != null);
......@@ -210,9 +210,9 @@ fn testUnion() void {
210210 };
211211
212212 const notag_union_info = @typeInfo(TestNoTagUnion);
213 expect(@as(TypeId, notag_union_info) == TypeId.Union);
213 expect(notag_union_info == .Union);
214214 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);
216216 expect(notag_union_info.Union.fields.len == 2);
217217 expect(notag_union_info.Union.fields[0].enum_field == null);
218218 expect(notag_union_info.Union.fields[1].field_type == u32);
......@@ -222,7 +222,7 @@ fn testUnion() void {
222222 };
223223
224224 const extern_union_info = @typeInfo(TestExternUnion);
225 expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
225 expect(extern_union_info.Union.layout == .Extern);
226226 expect(extern_union_info.Union.tag_type == null);
227227 expect(extern_union_info.Union.fields[0].enum_field == null);
228228 expect(extern_union_info.Union.fields[0].field_type == *c_void);
......@@ -235,8 +235,8 @@ test "type info: struct info" {
235235
236236fn testStruct() void {
237237 const struct_info = @typeInfo(TestStruct);
238 expect(@as(TypeId, struct_info) == TypeId.Struct);
239 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
238 expect(struct_info == .Struct);
239 expect(struct_info.Struct.layout == .Packed);
240240 expect(struct_info.Struct.fields.len == 4);
241241 expect(struct_info.Struct.fields[1].offset == null);
242242 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
......@@ -268,22 +268,20 @@ test "type info: function type info" {
268268
269269fn testFunction() void {
270270 const fn_info = @typeInfo(@TypeOf(foo));
271 expect(@as(TypeId, fn_info) == TypeId.Fn);
272 expect(fn_info.Fn.calling_convention == .Unspecified);
273 expect(fn_info.Fn.is_generic);
271 expect(fn_info == .Fn);
272 expect(fn_info.Fn.calling_convention == .C);
273 expect(!fn_info.Fn.is_generic);
274274 expect(fn_info.Fn.args.len == 2);
275275 expect(fn_info.Fn.is_var_args);
276 expect(fn_info.Fn.return_type == null);
276 expect(fn_info.Fn.return_type.? == usize);
277277
278278 const test_instance: TestStruct = undefined;
279279 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
280 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);
280 expect(bound_fn_info == .BoundFn);
281281 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
282282}
283283
284fn foo(comptime a: usize, b: bool, args: ...) usize {
285 return 0;
286}
284extern fn foo(a: usize, b: bool, args: ...) usize;
287285
288286test "typeInfo with comptime parameter in struct fn def" {
289287 const S = struct {
......@@ -299,7 +297,7 @@ test "type info: vectors" {
299297
300298fn testVector() void {
301299 const vec_info = @typeInfo(@Vector(4, i32));
302 expect(@as(TypeId, vec_info) == TypeId.Vector);
300 expect(vec_info == .Vector);
303301 expect(vec_info.Vector.len == 4);
304302 expect(vec_info.Vector.child == i32);
305303}
......@@ -312,13 +310,13 @@ test "type info: anyframe and anyframe->T" {
312310fn testAnyFrame() void {
313311 {
314312 const anyframe_info = @typeInfo(anyframe->i32);
315 expect(@as(TypeId, anyframe_info) == .AnyFrame);
313 expect(anyframe_info == .AnyFrame);
316314 expect(anyframe_info.AnyFrame.child.? == i32);
317315 }
318316
319317 {
320318 const anyframe_info = @typeInfo(anyframe);
321 expect(@as(TypeId, anyframe_info) == .AnyFrame);
319 expect(anyframe_info == .AnyFrame);
322320 expect(anyframe_info.AnyFrame.child == null);
323321 }
324322}