| author | |
| committer | |
| log | c2aeef04e564213d8ea57007a11451bf825ae883 |
| tree | f71b3421cbc13892cac4f0665ba49fa4d3f358b9 |
| parent | 5d96a58f1d02d162fdff3e0ef0d742ee1d5074a7 |
2 files changed, 23 insertions(+), 7 deletions(-)
src/Sema.zig+1-7| ... | @@ -31629,13 +31629,7 @@ fn analyzeIsNonErrComptimeOnly( | ... | @@ -31629,13 +31629,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 31629 | return .bool_false; | 31629 | return .bool_false; |
| 31630 | } | 31630 | } |
| 31631 | 31631 | ||
| 31632 | if (operand.toIndex()) |operand_inst| { | 31632 | if (operand == .undef) { |
| 31633 | switch (sema.air_instructions.items(.tag)[@intFromEnum(operand_inst)]) { | ||
| 31634 | .wrap_errunion_payload => return .bool_true, | ||
| 31635 | .wrap_errunion_err => return .bool_false, | ||
| 31636 | else => {}, | ||
| 31637 | } | ||
| 31638 | } else if (operand == .undef) { | ||
| 31639 | return .undef_bool; | 31633 | return .undef_bool; |
| 31640 | } else if (@intFromEnum(operand) < InternPool.static_len) { | 31634 | } else if (@intFromEnum(operand) < InternPool.static_len) { |
| 31641 | // None of the ref tags can be errors. | 31635 | // None of the ref tags can be errors. |
test/cases/error_union_variant_is_runtime_known.zig created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | // This tests that the variant of an error union is runtime-known when the value is runtime-known. | ||
| 2 | // This might seem obvious but previously the compiler special-cased the situation where a const | ||
| 3 | // was assigned a payload or error value, i.e. instead of another error union. | ||
| 4 | |||
| 5 | export fn foo() void { | ||
| 6 | var runtime_payload: u8 = 0; | ||
| 7 | _ = &runtime_payload; | ||
| 8 | const eu: error{a}!u8 = runtime_payload; | ||
| 9 | if (eu) |_| {} else |_| @compileError("analyzed"); | ||
| 10 | } | ||
| 11 | |||
| 12 | export fn bar() void { | ||
| 13 | var runtime_error: error{a} = error.a; | ||
| 14 | _ = &runtime_error; | ||
| 15 | const eu: error{a}!u8 = runtime_error; | ||
| 16 | if (eu) |_| @compileError("analyzed") else |_| {} | ||
| 17 | } | ||
| 18 | |||
| 19 | // error | ||
| 20 | // | ||
| 21 | // :9:29: error: analyzed | ||
| 22 | // :16:17: error: analyzed | ||