sema: error union in-memory coercion
This commit is contained in:
10
src/Sema.zig
10
src/Sema.zig
@@ -12415,6 +12415,15 @@ fn coerceInMemoryAllowed(dest_ty: Type, src_ty: Type, dest_is_mut: bool, target:
|
||||
return coerceInMemoryAllowedFns(dest_ty, src_ty, target);
|
||||
}
|
||||
|
||||
// Error Unions
|
||||
if (dest_ty.zigTypeTag() == .ErrorUnion and src_ty.zigTypeTag() == .ErrorUnion) {
|
||||
const child = coerceInMemoryAllowed(dest_ty.errorUnionPayload(), src_ty.errorUnionPayload(), dest_is_mut, target);
|
||||
if (child == .no_match) {
|
||||
return child;
|
||||
}
|
||||
return coerceInMemoryAllowed(dest_ty.errorUnionSet(), src_ty.errorUnionSet(), dest_is_mut, target);
|
||||
}
|
||||
|
||||
// Error Sets
|
||||
if (dest_ty.zigTypeTag() == .ErrorSet and src_ty.zigTypeTag() == .ErrorSet) {
|
||||
return coerceInMemoryAllowedErrorSets(dest_ty, src_ty);
|
||||
@@ -12422,7 +12431,6 @@ fn coerceInMemoryAllowed(dest_ty: Type, src_ty: Type, dest_is_mut: bool, target:
|
||||
|
||||
// TODO: arrays
|
||||
// TODO: non-pointer-like optionals
|
||||
// TODO: error unions
|
||||
// TODO: vectors
|
||||
|
||||
return .no_match;
|
||||
|
||||
@@ -115,3 +115,19 @@ test "implicit cast to optional to error union to return result loc" {
|
||||
try S.entry();
|
||||
//comptime S.entry(); TODO
|
||||
}
|
||||
|
||||
test "error: fn returning empty error set can be passed as fn returning any error" {
|
||||
entry();
|
||||
comptime entry();
|
||||
}
|
||||
|
||||
fn entry() void {
|
||||
foo2(bar2);
|
||||
}
|
||||
|
||||
fn foo2(f: fn () anyerror!void) void {
|
||||
const x = f();
|
||||
x catch {};
|
||||
}
|
||||
|
||||
fn bar2() (error{}!void) {}
|
||||
|
||||
@@ -120,22 +120,6 @@ fn quux_1() !i32 {
|
||||
return error.C;
|
||||
}
|
||||
|
||||
test "error: fn returning empty error set can be passed as fn returning any error" {
|
||||
entry();
|
||||
comptime entry();
|
||||
}
|
||||
|
||||
fn entry() void {
|
||||
foo2(bar2);
|
||||
}
|
||||
|
||||
fn foo2(f: fn () anyerror!void) void {
|
||||
const x = f();
|
||||
x catch {};
|
||||
}
|
||||
|
||||
fn bar2() (error{}!void) {}
|
||||
|
||||
test "error: Zero sized error set returned with value payload crash" {
|
||||
_ = foo3(0) catch {};
|
||||
_ = comptime foo3(0) catch {};
|
||||
|
||||
Reference in New Issue
Block a user