| author | |
| committer | |
| log | cb248898ab41378c2e9bcf94d05c7c42577a7bab |
| tree | 97d571db34045fe9a5dd1fe9e98d678e5b7f31cd |
| parent | 83a0329c92dc8302b7098f718ceed2ed00e9fda2 |
3 files changed, 25 insertions(+), 17 deletions(-)
src/Sema.zig+9-1| ... | ... | @@ -12415,6 +12415,15 @@ fn coerceInMemoryAllowed(dest_ty: Type, src_ty: Type, dest_is_mut: bool, target: |
| 12415 | 12415 | return coerceInMemoryAllowedFns(dest_ty, src_ty, target); |
| 12416 | 12416 | } |
| 12417 | 12417 | |
| 12418 | // Error Unions | |
| 12419 | if (dest_ty.zigTypeTag() == .ErrorUnion and src_ty.zigTypeTag() == .ErrorUnion) { | |
| 12420 | const child = coerceInMemoryAllowed(dest_ty.errorUnionPayload(), src_ty.errorUnionPayload(), dest_is_mut, target); | |
| 12421 | if (child == .no_match) { | |
| 12422 | return child; | |
| 12423 | } | |
| 12424 | return coerceInMemoryAllowed(dest_ty.errorUnionSet(), src_ty.errorUnionSet(), dest_is_mut, target); | |
| 12425 | } | |
| 12426 | ||
| 12418 | 12427 | // Error Sets |
| 12419 | 12428 | if (dest_ty.zigTypeTag() == .ErrorSet and src_ty.zigTypeTag() == .ErrorSet) { |
| 12420 | 12429 | return coerceInMemoryAllowedErrorSets(dest_ty, src_ty); |
| ... | ... | @@ -12422,7 +12431,6 @@ fn coerceInMemoryAllowed(dest_ty: Type, src_ty: Type, dest_is_mut: bool, target: |
| 12422 | 12431 | |
| 12423 | 12432 | // TODO: arrays |
| 12424 | 12433 | // TODO: non-pointer-like optionals |
| 12425 | // TODO: error unions | |
| 12426 | 12434 | // TODO: vectors |
| 12427 | 12435 | |
| 12428 | 12436 | return .no_match; |
test/behavior/error.zig+16| ... | ... | @@ -115,3 +115,19 @@ test "implicit cast to optional to error union to return result loc" { |
| 115 | 115 | try S.entry(); |
| 116 | 116 | //comptime S.entry(); TODO |
| 117 | 117 | } |
| 118 | ||
| 119 | test "error: fn returning empty error set can be passed as fn returning any error" { | |
| 120 | entry(); | |
| 121 | comptime entry(); | |
| 122 | } | |
| 123 | ||
| 124 | fn entry() void { | |
| 125 | foo2(bar2); | |
| 126 | } | |
| 127 | ||
| 128 | fn foo2(f: fn () anyerror!void) void { | |
| 129 | const x = f(); | |
| 130 | x catch {}; | |
| 131 | } | |
| 132 | ||
| 133 | fn bar2() (error{}!void) {} |
test/behavior/error_stage1.zig-16| ... | ... | @@ -120,22 +120,6 @@ fn quux_1() !i32 { |
| 120 | 120 | return error.C; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | test "error: fn returning empty error set can be passed as fn returning any error" { | |
| 124 | entry(); | |
| 125 | comptime entry(); | |
| 126 | } | |
| 127 | ||
| 128 | fn entry() void { | |
| 129 | foo2(bar2); | |
| 130 | } | |
| 131 | ||
| 132 | fn foo2(f: fn () anyerror!void) void { | |
| 133 | const x = f(); | |
| 134 | x catch {}; | |
| 135 | } | |
| 136 | ||
| 137 | fn bar2() (error{}!void) {} | |
| 138 | ||
| 139 | 123 | test "error: Zero sized error set returned with value payload crash" { |
| 140 | 124 | _ = foo3(0) catch {}; |
| 141 | 125 | _ = comptime foo3(0) catch {}; |