From 08a7ce7dd5f348b37bf98c5040ad58720a7818b5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 24 Dec 2015 13:47:07 -0700 Subject: add error for missing or duplicate field in struct value expr --- test/run_tests.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/run_tests.cpp') diff --git a/test/run_tests.cpp b/test/run_tests.cpp index f5f814de8b..f6a3c3dfec 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -877,6 +877,36 @@ struct A { y : i32, } struct A { x : i32, } export fn f(a : A) {} )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions"); + + add_compile_fail_case("duplicate field in struct value expression", R"SOURCE( +struct A { + x : i32, + y : i32, + z : i32, +} +fn f() { + const a = A { + .z = 1, + .y = 2, + .x = 3, + .z = 4, + }; +} + )SOURCE", 1, ".tmp_source.zig:12:9: error: duplicate field"); + + add_compile_fail_case("missing field in struct value expression", R"SOURCE( +struct A { + x : i32, + y : i32, + z : i32, +} +fn f() { + const a = A { + .z = 4, + .y = 2, + }; +} + )SOURCE", 1, ".tmp_source.zig:8:15: error: missing field: 'x'"); } static void print_compiler_invocation(TestCase *test_case) { -- cgit v1.2.3