diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:46:58 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:46:58 -0500 |
| commit | 960914a073c367883c9fdf54e900890a6aefc05f (patch) | |
| tree | 4dca5efa7967f0ecca20bd0d852005008a1ec925 /test/compile_errors.zig | |
| parent | 63a2f9a8b2251ffdc37d5f28dfbd3f6be1bd7908 (diff) | |
| download | zig-960914a073c367883c9fdf54e900890a6aefc05f.tar.gz zig-960914a073c367883c9fdf54e900890a6aefc05f.zip | |
add implicit cast from enum to union
when the enum is the tag type of the union and is comptime known
to be of a void field of the union
See #642
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 162109f4d8..8dbb8171c2 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2696,4 +2696,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) { , ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0", ".tmp_source.zig:1:13: note: 'Foo' declared here"); + + cases.add("comptime cast enum to union but field has payload", + \\const Letter = enum { A, B, C }; + \\const Value = union(Letter) { + \\ A: i32, + \\ B, + \\ C, + \\}; + \\export fn entry() { + \\ var x: Value = Letter.A; + \\} + , + ".tmp_source.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", + ".tmp_source.zig:3:5: note: field 'A' declared here"); + + cases.add("runtime cast to union which has non-void fields", + \\const Letter = enum { A, B, C }; + \\const Value = union(Letter) { + \\ A: i32, + \\ B, + \\ C, + \\}; + \\export fn entry() { + \\ foo(Letter.A); + \\} + \\fn foo(l: Letter) { + \\ var x: Value = l; + \\} + , + ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", + ".tmp_source.zig:3:5: note: field 'A' has type 'i32'"); } |
