Sema: fix issues in @errorCast with error unions

This commit is contained in:
Veikka Tuominen
2023-10-02 15:44:50 +03:00
committed by Andrew Kelley
parent c9c3ee704c
commit 0bdbd3e235
3 changed files with 46 additions and 9 deletions

View File

@@ -238,13 +238,23 @@ fn testExplicitErrorSetCast(set1: Set1) !void {
test "@errorCast on error unions" {
const S = struct {
fn doTheTest() !void {
const casted: error{Bad}!i32 = @errorCast(retErrUnion());
try expect((try casted) == 1234);
{
const casted: error{Bad}!i32 = @errorCast(retErrUnion());
try expect((try casted) == 1234);
}
{
const casted: error{Bad}!i32 = @errorCast(retInferredErrUnion());
try expect((try casted) == 5678);
}
}
fn retErrUnion() anyerror!i32 {
return 1234;
}
fn retInferredErrUnion() !i32 {
return 5678;
}
};
try S.doTheTest();