2019-02-08 23:18:47 +00:00
|
|
|
const expect = @import("std").testing.expect;
|
2022-03-09 17:26:48 +00:00
|
|
|
const builtin = @import("builtin");
|
2017-01-05 08:57:48 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const FormValue = union(enum) {
|
2017-12-04 01:43:56 +00:00
|
|
|
One: void,
|
2016-09-20 21:10:34 +01:00
|
|
|
Two: bool,
|
2016-12-25 23:31:57 +00:00
|
|
|
};
|
2016-09-20 21:10:34 +01:00
|
|
|
|
2018-02-01 03:48:40 +00:00
|
|
|
fn foo(id: u64) !FormValue {
|
2017-12-22 05:50:30 +00:00
|
|
|
return switch (id) {
|
2018-11-13 13:08:37 +00:00
|
|
|
2 => FormValue{ .Two = true },
|
|
|
|
1 => FormValue{ .One = {} },
|
2016-09-20 21:10:34 +01:00
|
|
|
else => return error.Whatever,
|
2017-12-22 05:50:30 +00:00
|
|
|
};
|
2016-09-20 21:10:34 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 02:38:31 +01:00
|
|
|
test "switch prong implicit cast" {
|
2022-03-09 17:26:48 +00:00
|
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
2022-10-11 14:39:47 +01:00
|
|
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
2023-05-11 06:53:34 +01:00
|
|
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
2022-10-11 14:39:47 +01:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
const result = switch (foo(2) catch unreachable) {
|
2016-12-25 23:31:57 +00:00
|
|
|
FormValue.One => false,
|
|
|
|
FormValue.Two => |x| x,
|
2016-09-20 21:10:34 +01:00
|
|
|
};
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(result);
|
2016-09-20 21:10:34 +01:00
|
|
|
}
|