| author | |
| committer | |
| log | fca51c81bc5fd83a3d4a87092696df80790003e9 |
| tree | 0b4a94cd45cc837a60e842afd3b3dff77827ee7b |
| parent | 797f4db227dcdbe48ffb309763a48fbe6eaf5935 |
2 files changed, 14 insertions(+), 1 deletions(-)
src/Sema.zig+9| ... | @@ -18144,6 +18144,15 @@ fn analyzeIsNonErr( | ... | @@ -18144,6 +18144,15 @@ fn analyzeIsNonErr( |
| 18144 | if (ot != .ErrorSet and ot != .ErrorUnion) return Air.Inst.Ref.bool_true; | 18144 | if (ot != .ErrorSet and ot != .ErrorUnion) return Air.Inst.Ref.bool_true; |
| 18145 | if (ot == .ErrorSet) return Air.Inst.Ref.bool_false; | 18145 | if (ot == .ErrorSet) return Air.Inst.Ref.bool_false; |
| 18146 | assert(ot == .ErrorUnion); | 18146 | assert(ot == .ErrorUnion); |
| 18147 | |||
| 18148 | // exception if the error union error set is known to be empty, | ||
| 18149 | // we allow the comparison but always make it comptime known. | ||
| 18150 | const set_ty = operand_ty.errorUnionSet(); | ||
| 18151 | switch (set_ty.tag()) { | ||
| 18152 | .anyerror, .error_set_inferred => {}, | ||
| 18153 | else => if (set_ty.errorSetNames().len == 0) return Air.Inst.Ref.bool_true, | ||
| 18154 | } | ||
| 18155 | |||
| 18147 | const result_ty = Type.bool; | 18156 | const result_ty = Type.bool; |
| 18148 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |err_union| { | 18157 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |err_union| { |
| 18149 | if (err_union.isUndef()) { | 18158 | if (err_union.isUndef()) { |
test/behavior/error.zig+5-1| ... | @@ -215,7 +215,11 @@ fn testExplicitErrorSetCast(set1: Set1) !void { | ... | @@ -215,7 +215,11 @@ fn testExplicitErrorSetCast(set1: Set1) !void { |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | test "comptime test error for empty error set" { | 217 | test "comptime test error for empty error set" { |
| 218 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | 218 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO |
| 219 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 220 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 221 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 222 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 219 | 223 | ||
| 220 | try testComptimeTestErrorEmptySet(1234); | 224 | try testComptimeTestErrorEmptySet(1234); |
| 221 | comptime try testComptimeTestErrorEmptySet(1234); | 225 | comptime try testComptimeTestErrorEmptySet(1234); |