From 5b279434986b18d07ceec217c5c402a589ccc0b4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Nov 2019 21:58:05 -0500 Subject: implement anon struct literal syntax This implements stage1 parser support for anonymous struct literal syntax (see #685), as well as semantic analysis support for anonymous struct literals and anonymous list literals (see #208). The semantic analysis works when there is a type coercion in the result location; inferring the struct type based on the values in the literal is not implemented yet. Also remaining to do is zig fmt support for this new syntax and documentation updates. --- test/compile_errors.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 0917c3dbb4..c64f5b38a5 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -216,9 +216,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const obj = AstObject{ .lhsExpr = lhsExpr }; \\} , - "tmp.zig:4:19: error: union 'AstObject' depends on itself", - "tmp.zig:2:5: note: while checking this field", + "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", "tmp.zig:5:5: note: while checking this field", + "tmp.zig:2:5: note: while checking this field", ); cases.add( -- cgit v1.2.3 From a33b9aec724dfce68889f6255a2c78572b47c92f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 11 Nov 2019 18:01:27 -0500 Subject: add test for missing const in slice with nested array type --- test/compile_errors.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index c64f5b38a5..1adf3c3f8e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,23 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "missing const in slice with nested array type", + \\const Geo3DTex2D = struct { vertices: [][2]f32 }; + \\pub fn getGeo3DTex2D() Geo3DTex2D { + \\ return Geo3DTex2D{ + \\ .vertices = [_][2]f32{ + \\ [_]f32{ -0.5, -0.5}, + \\ }, + \\ }; + \\} + \\export fn entry() void { + \\ var geo_data = getGeo3DTex2D(); + \\} + , + "tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32'", + ); + cases.add( "slicing of global undefined pointer", \\var buf: *[1]u8 = undefined; -- cgit v1.2.3