2017-01-05 00:57:48 -08:00
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2017-12-03 17:43:56 -08:00
|
|
|
const FormValue = union(enum) {
|
|
|
|
One: void,
|
2016-09-20 13:10:34 -07:00
|
|
|
Two: bool,
|
2016-12-25 15:31:57 -08:00
|
|
|
};
|
2016-09-20 13:10:34 -07:00
|
|
|
|
2018-01-31 19:48:40 -08:00
|
|
|
fn foo(id: u64) !FormValue {
|
2017-12-21 21:50:30 -08:00
|
|
|
return switch (id) {
|
2017-12-03 17:43:56 -08:00
|
|
|
2 => FormValue { .Two = true },
|
|
|
|
1 => FormValue { .One = {} },
|
2016-09-20 13:10:34 -07:00
|
|
|
else => return error.Whatever,
|
2017-12-21 21:50:30 -08:00
|
|
|
};
|
2016-09-20 13:10:34 -07:00
|
|
|
}
|
|
|
|
|
2017-05-23 18:38:31 -07:00
|
|
|
test "switch prong implicit cast" {
|
2018-01-08 21:07:01 -08:00
|
|
|
const result = switch (foo(2) catch unreachable) {
|
2016-12-25 15:31:57 -08:00
|
|
|
FormValue.One => false,
|
|
|
|
FormValue.Two => |x| x,
|
2016-09-20 13:10:34 -07:00
|
|
|
};
|
|
|
|
assert(result);
|
|
|
|
}
|