diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-02 17:12:37 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-02 17:12:37 -0500 |
| commit | 98237f7c0ba62099e85a8caf8fc09039845b224e (patch) | |
| tree | 4f0ecbc220a178747c330d457cc1388100bbed43 /test/compile_errors.zig | |
| parent | 54a0db0daf8fd5ef307f275275e10f32ebd7d27a (diff) | |
| download | zig-98237f7c0ba62099e85a8caf8fc09039845b224e.tar.gz zig-98237f7c0ba62099e85a8caf8fc09039845b224e.zip | |
casting between integer and enum only works via tag type
See #305
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 9b5ec6a6d6..367dec08b3 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2390,4 +2390,61 @@ pub fn addCases(cases: &tests.CompileErrorContext) { \\} , ".tmp_source.zig:1:20: error: expected integer, found 'f32'"); + + cases.add("implicitly casting enum to tag type", + \\const Small = enum(u2) { + \\ One, + \\ Two, + \\ Three, + \\ Four, + \\}; + \\ + \\export fn entry() { + \\ var x: u2 = Small.Two; + \\} + , + ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'"); + + cases.add("explicitly casting enum to non tag type", + \\const Small = enum(u2) { + \\ One, + \\ Two, + \\ Three, + \\ Four, + \\}; + \\ + \\export fn entry() { + \\ var x = u3(Small.Two); + \\} + , + ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'"); + + cases.add("explicitly casting non tag type to enum", + \\const Small = enum(u2) { + \\ One, + \\ Two, + \\ Three, + \\ Four, + \\}; + \\ + \\export fn entry() { + \\ var y = u3(3); + \\ var x = Small(y); + \\} + , + ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'"); + + cases.add("non unsigned integer enum tag type", + \\const Small = enum(i2) { + \\ One, + \\ Two, + \\ Three, + \\ Four, + \\}; + \\ + \\export fn entry() { + \\ var y = Small.Two; + \\} + , + ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'"); } |
