2016-12-25 23:31:57 +00:00
|
|
|
const FormValue = enum {
|
2016-09-20 21:10:34 +01:00
|
|
|
One,
|
|
|
|
Two: bool,
|
2016-12-25 23:31:57 +00:00
|
|
|
};
|
2016-09-20 21:10:34 +01:00
|
|
|
|
|
|
|
error Whatever;
|
|
|
|
|
|
|
|
fn foo(id: u64) -> %FormValue {
|
|
|
|
switch (id) {
|
|
|
|
2 => FormValue.Two { true },
|
|
|
|
1 => FormValue.One,
|
|
|
|
else => return error.Whatever,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn switchProngImplicitCast() {
|
2016-12-25 23:31:57 +00:00
|
|
|
@setFnTest(this);
|
2016-09-28 07:33:32 +01:00
|
|
|
|
2016-09-20 21:10:34 +01:00
|
|
|
const result = switch (%%foo(2)) {
|
2016-12-25 23:31:57 +00:00
|
|
|
FormValue.One => false,
|
|
|
|
FormValue.Two => |x| x,
|
2016-09-20 21:10:34 +01:00
|
|
|
};
|
|
|
|
assert(result);
|
|
|
|
}
|
2016-12-25 23:31:57 +00:00
|
|
|
|
|
|
|
// TODO const assert = @import("std").debug.assert;
|
|
|
|
fn assert(ok: bool) {
|
|
|
|
if (!ok)
|
|
|
|
@unreachable();
|
|
|
|
}
|