| ... | ... | @@ -16356,6 +16356,15 @@ fn finishCondBr( |
| 16356 | 16356 | return Air.indexToRef(block_inst); |
| 16357 | 16357 | } |
| 16358 | 16358 | |
| 16359 | fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 16360 | switch (ty.zigTypeTag()) { |
| 16361 | .Optional, .Null, .Undefined => return, |
| 16362 | .Pointer => if (ty.isPtrLikeOptional()) return, |
| 16363 | else => {}, |
| 16364 | } |
| 16365 | return sema.failWithExpectedOptionalType(block, src, ty); |
| 16366 | } |
| 16367 | |
| 16359 | 16368 | fn zirIsNonNull( |
| 16360 | 16369 | sema: *Sema, |
| 16361 | 16370 | block: *Block, |
| ... | ... | @@ -16367,6 +16376,7 @@ fn zirIsNonNull( |
| 16367 | 16376 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16368 | 16377 | const src = inst_data.src(); |
| 16369 | 16378 | const operand = try sema.resolveInst(inst_data.operand); |
| 16379 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| 16370 | 16380 | return sema.analyzeIsNull(block, src, operand, true); |
| 16371 | 16381 | } |
| 16372 | 16382 | |
| ... | ... | @@ -16381,6 +16391,7 @@ fn zirIsNonNullPtr( |
| 16381 | 16391 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16382 | 16392 | const src = inst_data.src(); |
| 16383 | 16393 | const ptr = try sema.resolveInst(inst_data.operand); |
| 16394 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2()); |
| 16384 | 16395 | if ((try sema.resolveMaybeUndefVal(ptr)) == null) { |
| 16385 | 16396 | return block.addUnOp(.is_non_null_ptr, ptr); |
| 16386 | 16397 | } |
| ... | ... | @@ -16388,12 +16399,23 @@ fn zirIsNonNullPtr( |
| 16388 | 16399 | return sema.analyzeIsNull(block, src, loaded, true); |
| 16389 | 16400 | } |
| 16390 | 16401 | |
| 16402 | fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 16403 | switch (ty.zigTypeTag()) { |
| 16404 | .ErrorSet, .ErrorUnion, .Undefined => return, |
| 16405 | else => return sema.fail(block, src, "expected error union type, found '{}'", .{ |
| 16406 | ty.fmt(sema.mod), |
| 16407 | }), |
| 16408 | } |
| 16409 | } |
| 16410 | |
| 16391 | 16411 | fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16392 | 16412 | const tracy = trace(@src()); |
| 16393 | 16413 | defer tracy.end(); |
| 16394 | 16414 | |
| 16395 | 16415 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16416 | const src = inst_data.src(); |
| 16396 | 16417 | const operand = try sema.resolveInst(inst_data.operand); |
| 16418 | try sema.checkErrorType(block, src, sema.typeOf(operand)); |
| 16397 | 16419 | return sema.analyzeIsNonErr(block, inst_data.src(), operand); |
| 16398 | 16420 | } |
| 16399 | 16421 | |
| ... | ... | @@ -16404,6 +16426,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 16404 | 16426 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16405 | 16427 | const src = inst_data.src(); |
| 16406 | 16428 | const ptr = try sema.resolveInst(inst_data.operand); |
| 16429 | try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2()); |
| 16407 | 16430 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| 16408 | 16431 | return sema.analyzeIsNonErr(block, src, loaded); |
| 16409 | 16432 | } |