diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-29 00:40:02 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-08-29 13:45:37 -0700 |
| commit | a4b52ccd9fb538bdcd77cf2d45b9310e189cc243 (patch) | |
| tree | f87cb9fef812ba510ab6938eff266010cd7343e2 /test/cases/compile_errors | |
| parent | 15cc4514e0566430ed1d95e85aaa462642b70364 (diff) | |
| download | zig-a4b52ccd9fb538bdcd77cf2d45b9310e189cc243.tar.gz zig-a4b52ccd9fb538bdcd77cf2d45b9310e189cc243.zip | |
Sema: fix access of inactive union field when enum and union fields are in different order
Closes #12667
Diffstat (limited to 'test/cases/compile_errors')
| -rw-r--r-- | test/cases/compile_errors/access_inactive_union_field_comptime.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/cases/compile_errors/access_inactive_union_field_comptime.zig b/test/cases/compile_errors/access_inactive_union_field_comptime.zig new file mode 100644 index 0000000000..d990a85f9e --- /dev/null +++ b/test/cases/compile_errors/access_inactive_union_field_comptime.zig @@ -0,0 +1,23 @@ +const Enum = enum(u32) { a, b }; +const TaggedUnion = union(Enum) { + b: []const u8, + a: []const u8, +}; +pub export fn entry() void { + const result = TaggedUnion{ .b = "b" }; + _ = result.b; + _ = result.a; +} +pub export fn entry1() void { + const result = TaggedUnion{ .b = "b" }; + _ = &result.b; + _ = &result.a; +} + +// error +// backend=stage2 +// target=native +// +// :9:15: error: access of union field 'a' while field 'b' is active +// :2:21: note: union declared here +// :14:16: error: access of union field 'a' while field 'b' is active |
