| ... | @@ -6684,8 +6684,13 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -6684,8 +6684,13 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 6684 | defer tracy.end(); | 6684 | defer tracy.end(); |
| 6685 | | 6685 | |
| 6686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 6686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 6687 | const src = inst_data.src(); | 6687 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 6688 | const child_type = try sema.resolveType(block, src, inst_data.operand); | 6688 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| | 6689 | if (child_type.zigTypeTag() == .Opaque) { |
| | 6690 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(sema.mod)}); |
| | 6691 | } else if (child_type.zigTypeTag() == .Null) { |
| | 6692 | return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(sema.mod)}); |
| | 6693 | } |
| 6689 | const opt_type = try Type.optional(sema.arena, child_type); | 6694 | const opt_type = try Type.optional(sema.arena, child_type); |
| 6690 | | 6695 | |
| 6691 | return sema.addType(opt_type); | 6696 | return sema.addType(opt_type); |
| ... | @@ -25714,6 +25719,12 @@ fn analyzeIsNull( | ... | @@ -25714,6 +25719,12 @@ fn analyzeIsNull( |
| 25714 | return Air.Inst.Ref.bool_false; | 25719 | return Air.Inst.Ref.bool_false; |
| 25715 | } | 25720 | } |
| 25716 | } | 25721 | } |
| | 25722 | |
| | 25723 | const operand_ty = sema.typeOf(operand); |
| | 25724 | var buf: Type.Payload.ElemType = undefined; |
| | 25725 | if (operand_ty.zigTypeTag() == .Optional and operand_ty.optionalChild(&buf).zigTypeTag() == .NoReturn) { |
| | 25726 | return Air.Inst.Ref.bool_true; |
| | 25727 | } |
| 25717 | try sema.requireRuntimeBlock(block, src, null); | 25728 | try sema.requireRuntimeBlock(block, src, null); |
| 25718 | const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null; | 25729 | const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null; |
| 25719 | return block.addUnOp(air_tag, operand); | 25730 | return block.addUnOp(air_tag, operand); |