test/stack_traces.zig: add err union switch case

This commit is contained in:
dweiller 2024-01-18 13:29:44 +11:00
parent 7ef3d3876a
commit c4cff443b8

View File

@ -807,4 +807,59 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
,
},
});
cases.addCase(.{
.name = "error union switch with call operand",
.source =
\\pub fn main() !void {
\\ try foo();
\\ return error.TheSkyIsFalling;
\\}
\\
\\noinline fn failure() error{ Fatal, NonFatal }!void {
\\ return error.NonFatal;
\\}
\\
\\fn foo() error{Fatal}!void {
\\ return failure() catch |err| switch (err) {
\\ error.Fatal => return error.Fatal,
\\ error.NonFatal => return,
\\ };
\\}
,
.Debug = .{
.expect =
\\error: TheSkyIsFalling
\\source.zig:3:5: [address] in main (test)
\\ return error.TheSkyIsFalling;
\\ ^
\\
,
},
.ReleaseSafe = .{
.exclude_os = &.{
.windows, // TODO
.linux, // defeated by aggressive inlining
},
.expect =
\\error: TheSkyIsFalling
\\source.zig:3:5: [address] in [function]
\\ return error.TheSkyIsFalling;
\\ ^
\\
,
.error_tracing = true,
},
.ReleaseFast = .{
.expect =
\\error: TheSkyIsFalling
\\
,
},
.ReleaseSmall = .{
.expect =
\\error: TheSkyIsFalling
\\
,
},
});
}