diff options
Diffstat (limited to 'test/compile_errors')
4 files changed, 75 insertions, 0 deletions
diff --git a/test/compile_errors/stage2/union_access_of_inactive_field.zig b/test/compile_errors/stage2/union_access_of_inactive_field.zig new file mode 100644 index 0000000000..34fa661d79 --- /dev/null +++ b/test/compile_errors/stage2/union_access_of_inactive_field.zig @@ -0,0 +1,14 @@ +const U = union { + a: void, + b: u64, +}; +comptime { + var u: U = .{.a = {}}; + const v = u.b; + _ = v; +} + +// access of inactive union field +// +// :7:16: error: access of union field 'b' while field 'a' is active +// :1:11: note: union declared here diff --git a/test/compile_errors/stage2/union_enum_field_missing.zig b/test/compile_errors/stage2/union_enum_field_missing.zig new file mode 100644 index 0000000000..b29ca83d3a --- /dev/null +++ b/test/compile_errors/stage2/union_enum_field_missing.zig @@ -0,0 +1,20 @@ +const E = enum { + a, + b, + c, +}; + +const U = union(E) { + a: i32, + b: f64, +}; + +export fn entry() usize { + return @sizeOf(U); +} + +// enum field missing in union +// +// :7:1: error: enum field(s) missing in union +// :4:5: note: field 'c' missing, declared here +// :1:11: note: enum declared here diff --git a/test/compile_errors/stage2/union_extra_field.zig b/test/compile_errors/stage2/union_extra_field.zig new file mode 100644 index 0000000000..4a0ab41936 --- /dev/null +++ b/test/compile_errors/stage2/union_extra_field.zig @@ -0,0 +1,19 @@ +const E = enum { + a, + b, + c, +}; +const U = union(E) { + a: i32, + b: f64, + c: f64, + d: f64, +}; +export fn entry() usize { + return @sizeOf(U); +} + +// union extra field +// +// :6:1: error: enum 'tmp.E' hs no field named 'd' +// :1:11: note: enum declared here diff --git a/test/compile_errors/stage2/union_runtime_coercion_from_enum.zig b/test/compile_errors/stage2/union_runtime_coercion_from_enum.zig new file mode 100644 index 0000000000..f7e96834fd --- /dev/null +++ b/test/compile_errors/stage2/union_runtime_coercion_from_enum.zig @@ -0,0 +1,22 @@ +const E = enum { + a, + b, +}; +const U = union(E) { + a: u32, + b: u64, +}; +fn foo() E { + return E.b; +} +export fn doTheTest() u64 { + var u: U = foo(); + return u.b; +} + +// runtime coercion from enum to union +// +// :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields +// :6:5: note: field 'a' has type 'u32' +// :7:5: note: field 'b' has type 'u64' +// :5:11: note: union declared here |
