| ... | @@ -9065,10 +9065,14 @@ fn zirOptionalPayload( | ... | @@ -9065,10 +9065,14 @@ fn zirOptionalPayload( |
| 9065 | }; | 9065 | }; |
| 9066 | | 9066 | |
| 9067 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 9067 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 9068 | return if (val.optionalValue(zcu)) |payload| | 9068 | if (val.optionalValue(zcu)) |payload| return Air.internedToRef(payload.toIntern()); |
| 9069 | Air.internedToRef(payload.toIntern()) | 9069 | if (block.isComptime()) return sema.fail(block, src, "unable to unwrap null", .{}); |
| 9070 | else | 9070 | if (safety_check and block.wantSafety()) { |
| 9071 | sema.fail(block, src, "unable to unwrap null", .{}); | 9071 | try sema.safetyPanic(block, src, .unwrap_null); |
| | 9072 | } else { |
| | 9073 | _ = try block.addNoOp(.unreach); |
| | 9074 | } |
| | 9075 | return .unreachable_value; |
| 9072 | } | 9076 | } |
| 9073 | | 9077 | |
| 9074 | try sema.requireRuntimeBlock(block, src, null); | 9078 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -36443,7 +36447,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -36443,7 +36447,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36443 | .type_int_unsigned, // u0 handled above | 36447 | .type_int_unsigned, // u0 handled above |
| 36444 | .type_pointer, | 36448 | .type_pointer, |
| 36445 | .type_slice, | 36449 | .type_slice, |
| 36446 | .type_optional, // ?noreturn handled above | | |
| 36447 | .type_anyframe, | 36450 | .type_anyframe, |
| 36448 | .type_error_union, | 36451 | .type_error_union, |
| 36449 | .type_anyerror_union, | 36452 | .type_anyerror_union, |
| ... | @@ -36655,6 +36658,15 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -36655,6 +36658,15 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36655 | | 36658 | |
| 36656 | else => unreachable, | 36659 | else => unreachable, |
| 36657 | }, | 36660 | }, |
| | 36661 | |
| | 36662 | .type_optional => { |
| | 36663 | const payload_ip = ip.indexToKey(ty.toIntern()).opt_type; |
| | 36664 | // Although ?noreturn is handled above, the element type |
| | 36665 | // can be effectively noreturn for example via an empty |
| | 36666 | // enum or error set. |
| | 36667 | if (ip.isNoReturn(payload_ip)) return try pt.nullValue(ty); |
| | 36668 | return null; |
| | 36669 | }, |
| 36658 | }, | 36670 | }, |
| 36659 | }; | 36671 | }; |
| 36660 | } | 36672 | } |