diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-04-19 17:15:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-04-19 17:15:55 -0700 |
| commit | 4e37fb2fa244e350b4e248332848d40594eee820 (patch) | |
| tree | 02de8b32d21a4b673484d69a1f7e223b48bdd523 /test/self_hosted.zig | |
| parent | 9658c05fd406a13cade56b9c6e26d96764b965cc (diff) | |
| download | zig-4e37fb2fa244e350b4e248332848d40594eee820.tar.gz zig-4e37fb2fa244e350b4e248332848d40594eee820.zip | |
implement constant initialization of enum values
see #5
Diffstat (limited to 'test/self_hosted.zig')
| -rw-r--r-- | test/self_hosted.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/self_hosted.zig b/test/self_hosted.zig index bfc43a3227..92f87c1f99 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -1204,3 +1204,43 @@ fn const_expression_eval_handling_of_variables() { x = false; } } + + + +#attribute("test") +fn constant_enum_initialization_with_differing_sizes() { + test3_1(test3_foo); + test3_2(test3_bar); +} +enum Test3Foo { + One, + Two: f32, + Three: Test3Point, +} +struct Test3Point { + x: i32, + y: i32, +} +const test3_foo = Test3Foo.Three(Test3Point {.x = 3, .y = 4}); +const test3_bar = Test3Foo.Two(13); +#static_eval_enable(false) +fn test3_1(f: Test3Foo) { + switch (f) { + Three => |pt| { + assert(pt.x == 3); + assert(pt.y == 4); + }, + else => unreachable{}, + } +} +#static_eval_enable(false) +fn test3_2(f: Test3Foo) { + switch (f) { + Two => |x| { + assert(x == 13); + }, + else => unreachable{}, + } +} + + |
