From cae49b1b9d40e106f52c8f80c00019138961bf89 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sat, 26 Sep 2020 08:06:14 -0600 Subject: [PATCH] Add tests for enums with explicit extern-allowed tag types in extern types --- test/compile_errors.zig | 12 ++++++++++++ test/stage1/behavior/bugs/1467.zig | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 test/stage1/behavior/bugs/1467.zig diff --git a/test/compile_errors.zig b/test/compile_errors.zig index fef0a64762..90ed504eac 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -20,6 +20,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", }); + cases.add("extern struct with non-extern-compatible integer tag type", + \\pub const E = enum(u31) { A, B, C }; + \\pub const S = extern struct { + \\ e: E, + \\}; + \\export fn entry() void { + \\ const s: S = undefined; + \\} + , &[_][]const u8{ + "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", + }); + cases.add("@Type for exhaustive enum with non-integer tag type", \\const TypeInfo = @import("builtin").TypeInfo; \\const Tag = @Type(.{ diff --git a/test/stage1/behavior/bugs/1467.zig b/test/stage1/behavior/bugs/1467.zig new file mode 100644 index 0000000000..71c55dc59c --- /dev/null +++ b/test/stage1/behavior/bugs/1467.zig @@ -0,0 +1,7 @@ +pub const E = enum(u32) { A, B, C }; +pub const S = extern struct { + e: E, +}; +test "bug 1467" { + const s: S = undefined; +}