aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-02 21:06:09 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-02 21:06:09 -0700
commitd47f0abd5b5ba95bacd2d573aeabcc53db8c8fc3 (patch)
tree18e901d51e99848a038e0e81eb412829b1069978 /test
parent97d7fddfb78d17132749cae59fea36fe661bf642 (diff)
downloadzig-d47f0abd5b5ba95bacd2d573aeabcc53db8c8fc3.tar.gz
zig-d47f0abd5b5ba95bacd2d573aeabcc53db8c8fc3.zip
stage2: Sema: implement validate_struct_init_ptr
Diffstat (limited to 'test')
-rw-r--r--test/stage2/cbe.zig45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig
index a80b904ae4..6efb5a5e7f 100644
--- a/test/stage2/cbe.zig
+++ b/test/stage2/cbe.zig
@@ -481,6 +481,51 @@ pub fn addCases(ctx: *TestContext) !void {
\\}
, "");
}
+
+ {
+ var case = ctx.exeFromCompiledC("structs", .{});
+ case.addError(
+ \\const Point = struct { x: i32, y: i32 };
+ \\export fn main() c_int {
+ \\ var p: Point = .{
+ \\ .y = 24,
+ \\ .x = 12,
+ \\ .y = 24,
+ \\ };
+ \\ return p.y - p.x - p.x;
+ \\}
+ , &.{
+ ":6:10: error: duplicate field",
+ ":4:10: note: other field here",
+ });
+ case.addError(
+ \\const Point = struct { x: i32, y: i32 };
+ \\export fn main() c_int {
+ \\ var p: Point = .{
+ \\ .y = 24,
+ \\ };
+ \\ return p.y - p.x - p.x;
+ \\}
+ , &.{
+ ":3:21: error: mising struct field: x",
+ ":1:15: note: 'Point' declared here",
+ });
+ case.addError(
+ \\const Point = struct { x: i32, y: i32 };
+ \\export fn main() c_int {
+ \\ var p: Point = .{
+ \\ .x = 12,
+ \\ .y = 24,
+ \\ .z = 48,
+ \\ };
+ \\ return p.y - p.x - p.x;
+ \\}
+ , &.{
+ ":6:10: error: no field named 'z' in struct 'Point'",
+ ":1:15: note: 'Point' declared here",
+ });
+ }
+
ctx.c("empty start function", linux_x64,
\\export fn _start() noreturn {
\\ unreachable;