From 4e37fb2fa244e350b4e248332848d40594eee820 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Apr 2016 17:15:36 -0700 Subject: implement constant initialization of enum values see #5 --- test/self_hosted.zig | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test') 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{}, + } +} + + -- cgit v1.2.3