authorgravatar for pentuppup@noreply.codeberg.orgpentuppup <pentuppup@noreply.codeberg.org> 2025-12-05 14:07:40-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-08 14:59:55+01:00
logc2aeef04e564213d8ea57007a11451bf825ae883
treef71b3421cbc13892cac4f0665ba49fa4d3f358b9
parent5d96a58f1d02d162fdff3e0ef0d742ee1d5074a7

sema: remove special case check in `is_non_err`


2 files changed, 23 insertions(+), 7 deletions(-)

src/Sema.zig+1-7
......@@ -31629,13 +31629,7 @@ fn analyzeIsNonErrComptimeOnly(
3162931629 return .bool_false;
3163031630 }
3163131631
31632 if (operand.toIndex()) |operand_inst| {
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) {
31632 if (operand == .undef) {
3163931633 return .undef_bool;
3164031634 } else if (@intFromEnum(operand) < InternPool.static_len) {
3164131635 // 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
5export 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
12export 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