diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-17 15:07:20 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-17 22:07:48 +0300 |
| commit | c3d5428cba4d02afbe1ec34bdc7bcb68f56d1b45 (patch) | |
| tree | cc185813723d14c8f480762ce2f9c1bda096b30b /test/cases/compile_errors | |
| parent | b0a55e1b3be3a274546f9c18016e9609d546bdb0 (diff) | |
| download | zig-c3d5428cba4d02afbe1ec34bdc7bcb68f56d1b45.tar.gz zig-c3d5428cba4d02afbe1ec34bdc7bcb68f56d1b45.zip | |
Sema: properly handle noreturn fields in unions
Diffstat (limited to 'test/cases/compile_errors')
3 files changed, 55 insertions, 2 deletions
diff --git a/test/cases/compile_errors/noreturn_struct_field.zig b/test/cases/compile_errors/noreturn_struct_field.zig new file mode 100644 index 0000000000..90b243c31d --- /dev/null +++ b/test/cases/compile_errors/noreturn_struct_field.zig @@ -0,0 +1,12 @@ +const S = struct { + s: noreturn, +}; +comptime { + _ = @typeInfo(S); +} + +// error +// backend=stage2 +// target=native +// +// :2:5: error: struct fields cannot be 'noreturn' diff --git a/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig b/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig index c312d6db40..0142f422f4 100644 --- a/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig +++ b/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig @@ -18,6 +18,4 @@ fn foo(l: Letter) void { // // :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields // :3:5: note: field 'A' has type 'i32' -// :4:5: note: field 'B' has type 'void' -// :5:5: note: field 'C' has type 'void' // :2:15: note: union declared here diff --git a/test/cases/compile_errors/union_noreturn_field_initialized.zig b/test/cases/compile_errors/union_noreturn_field_initialized.zig new file mode 100644 index 0000000000..66304d6a74 --- /dev/null +++ b/test/cases/compile_errors/union_noreturn_field_initialized.zig @@ -0,0 +1,43 @@ +pub export fn entry1() void { + const U = union(enum) { + a: u32, + b: noreturn, + fn foo(_: @This()) void {} + fn bar() noreturn { + unreachable; + } + }; + + var a = U{ .b = undefined }; + _ = a; +} +pub export fn entry2() void { + const U = union(enum) { + a: noreturn, + }; + var u: U = undefined; + u = .a; +} +pub export fn entry3() void { + const U = union(enum) { + a: noreturn, + b: void, + }; + var e = @typeInfo(U).Union.tag_type.?.a; + var u: U = undefined; + u = e; +} + +// error +// backend=stage2 +// target=native +// +// :11:21: error: cannot initialize 'noreturn' field of union +// :4:9: note: field 'b' declared here +// :2:15: note: union declared here +// :19:10: error: cannot initialize 'noreturn' field of union +// :16:9: note: field 'a' declared here +// :15:15: note: union declared here +// :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field +// :23:9: note: 'noreturn' field here +// :22:15: note: union declared here |
