authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-05 14:55:36+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-06 15:39:06+03:00
logcc89908e826882065eeaa23bb8827fb7d7cd6219
treedb08db6e065b427aaaa5e22069ea2fc8a545d425
parent0b1dd845d9ac15ade5748dcb6ffa6b868fdfe0c0

Sema: do not emit `is(_non)_null` for invalid types

Closes #13024

1 files changed, 5 insertions(+), 1 deletions(-)

src/Sema.zig+5-1
...@@ -26897,10 +26897,14 @@ fn analyzeIsNull(...@@ -26897,10 +26897,14 @@ fn analyzeIsNull(
26897 }26897 }
26898 }26898 }
2689926899
26900 const inverted_non_null_res = if (invert_logic) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
26900 const operand_ty = sema.typeOf(operand);26901 const operand_ty = sema.typeOf(operand);
26901 var buf: Type.Payload.ElemType = undefined;26902 var buf: Type.Payload.ElemType = undefined;
26902 if (operand_ty.zigTypeTag() == .Optional and operand_ty.optionalChild(&buf).zigTypeTag() == .NoReturn) {26903 if (operand_ty.zigTypeTag() == .Optional and operand_ty.optionalChild(&buf).zigTypeTag() == .NoReturn) {
26903 return Air.Inst.Ref.bool_true;26904 return inverted_non_null_res;
26905 }
26906 if (operand_ty.zigTypeTag() != .Optional and !operand_ty.isPtrLikeOptional()) {
26907 return inverted_non_null_res;
26904 }26908 }
26905 try sema.requireRuntimeBlock(block, src, null);26909 try sema.requireRuntimeBlock(block, src, null);
26906 const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null;26910 const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null;