aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-05 18:09:22 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-05 18:09:22 -0500
commit63a2f9a8b2251ffdc37d5f28dfbd3f6be1bd7908 (patch)
tree799f7a95b9cda222a9242aaa5d866c38ace5effc /test
parent74cea89fce2af41d2af7379ff526d7046c4d8d77 (diff)
downloadzig-63a2f9a8b2251ffdc37d5f28dfbd3f6be1bd7908.tar.gz
zig-63a2f9a8b2251ffdc37d5f28dfbd3f6be1bd7908.zip
fix casting integer literal to enum
Diffstat (limited to 'test')
-rw-r--r--test/cases/enum.zig5
-rw-r--r--test/compile_errors.zig12
2 files changed, 17 insertions, 0 deletions
diff --git a/test/cases/enum.zig b/test/cases/enum.zig
index ec900511eb..d15614f9fd 100644
--- a/test/cases/enum.zig
+++ b/test/cases/enum.zig
@@ -344,3 +344,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) {
MultipleChoice2.Unspecified5 => 9,
});
}
+
+test "cast integer literal to enum" {
+ assert(MultipleChoice2(0) == MultipleChoice2.Unspecified1);
+ assert(MultipleChoice2(40) == MultipleChoice2.B);
+}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 5d13ed8d48..162109f4d8 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2684,4 +2684,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
,
".tmp_source.zig:11:13: error: switch on union which has no attached enum",
".tmp_source.zig:1:17: note: consider 'union(enum)' here");
+
+ cases.add("enum in field count range but not matching tag",
+ \\const Foo = enum(u32) {
+ \\ A = 10,
+ \\ B = 11,
+ \\};
+ \\export fn entry() {
+ \\ var x = Foo(0);
+ \\}
+ ,
+ ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0",
+ ".tmp_source.zig:1:13: note: 'Foo' declared here");
}