zig/test/cases/switch_prong_implicit_cast.zig
Andrew Kelley b581da41f8 remove compiler directives
* add `setFnTest`, `setFnVisible`, `setFnStaticEval`,
   `setFnNoInline` builtin functions to replace previous
   directive functionality
 * add `coldcc` and `nakedcc` as keywords which can be used as part
   of a function prototype.
 * `setDebugSafety` builtin can be used to set debug safety features
   at a per block scope level.
 * closes #169
2016-09-28 02:33:32 -04:00

29 lines
477 B
Zig

const assert = @import("std").debug.assert;
enum FormValue {
One,
Two: bool,
}
error Whatever;
fn foo(id: u64) -> %FormValue {
@setFnStaticEval(this, false);
switch (id) {
2 => FormValue.Two { true },
1 => FormValue.One,
else => return error.Whatever,
}
}
fn switchProngImplicitCast() {
@setFnTest(this, true);
const result = switch (%%foo(2)) {
One => false,
Two => |x| x,
};
assert(result);
}