From 78f32259daa79aaced1c49bcdace936121a2ccc5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 30 May 2019 15:35:30 -0400 Subject: default struct field initialization expressions closes #485 --- test/compile_errors.zig | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index fbecacb94b..7ee5896568 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,21 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "compile error in struct init expression", + \\const Foo = struct { + \\ a: i32 = crap, + \\ b: i32, + \\}; + \\export fn entry() void { + \\ var x = Foo{ + \\ .b = 5, + \\ }; + \\} + , + "tmp.zig:2:14: error: use of undeclared identifier 'crap'", + ); + cases.add( "undefined as field type is rejected", \\const Foo = struct { @@ -5484,18 +5499,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:10:31: error: expected type 'u2', found 'u3'", ); - cases.add( - "struct fields with value assignments", - \\const MultipleChoice = struct { - \\ A: i32 = 20, - \\}; - \\export fn entry() void { - \\ var x: MultipleChoice = undefined; - \\} - , - "tmp.zig:2:14: error: enums, not structs, support field assignment", - ); - cases.add( "union fields with value assignments", \\const MultipleChoice = union { -- cgit v1.2.3