2017-01-05 16:57:48 +08:00
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2016-12-26 07:31:57 +08:00
|
|
|
const FormValue = enum {
|
2016-09-21 04:10:34 +08:00
|
|
|
One,
|
|
|
|
Two: bool,
|
2016-12-26 07:31:57 +08:00
|
|
|
};
|
2016-09-21 04:10:34 +08:00
|
|
|
|
|
|
|
error Whatever;
|
|
|
|
|
|
|
|
fn foo(id: u64) -> %FormValue {
|
|
|
|
switch (id) {
|
|
|
|
2 => FormValue.Two { true },
|
|
|
|
1 => FormValue.One,
|
|
|
|
else => return error.Whatever,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 09:38:31 +08:00
|
|
|
test "switch prong implicit cast" {
|
2016-09-21 04:10:34 +08:00
|
|
|
const result = switch (%%foo(2)) {
|
2016-12-26 07:31:57 +08:00
|
|
|
FormValue.One => false,
|
|
|
|
FormValue.Two => |x| x,
|
2016-09-21 04:10:34 +08:00
|
|
|
};
|
|
|
|
assert(result);
|
|
|
|
}
|