| ... | ... | @@ -19741,6 +19741,14 @@ fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi |
| 19741 | 19741 | return sema.failWithExpectedOptionalType(block, src, ty); |
| 19742 | 19742 | } |
| 19743 | 19743 | |
| 19744 | fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 19745 | const pt = sema.pt; |
| 19746 | const zcu = pt.zcu; |
| 19747 | if (!ty.isSelfComparable(zcu, true)) { |
| 19748 | return sema.fail(block, src, "non-scalar sentinel type '{}'", .{ty.fmt(pt)}); |
| 19749 | } |
| 19750 | } |
| 19751 | |
| 19744 | 19752 | fn zirIsNonNull( |
| 19745 | 19753 | sema: *Sema, |
| 19746 | 19754 | block: *Block, |
| ... | ... | @@ -20542,6 +20550,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20542 | 20550 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ |
| 20543 | 20551 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", |
| 20544 | 20552 | }); |
| 20553 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 20545 | 20554 | break :blk val.toIntern(); |
| 20546 | 20555 | } else .none; |
| 20547 | 20556 | |
| ... | ... | @@ -28114,13 +28123,9 @@ fn panicSentinelMismatch( |
| 28114 | 28123 | .operation = .And, |
| 28115 | 28124 | } }, |
| 28116 | 28125 | }); |
| 28117 | | } else if (sentinel_ty.isSelfComparable(zcu, true)) |
| 28118 | | try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel) |
| 28119 | | else { |
| 28120 | | const panic_fn = try pt.getBuiltin("checkNonScalarSentinel"); |
| 28121 | | const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel }; |
| 28122 | | try sema.callBuiltin(parent_block, src, panic_fn, .auto, &args, .@"safety check"); |
| 28123 | | return; |
| 28126 | } else ok: { |
| 28127 | assert(sentinel_ty.isSelfComparable(zcu, true)); |
| 28128 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); |
| 28124 | 28129 | }; |
| 28125 | 28130 | |
| 28126 | 28131 | if (!pt.zcu.comp.formatted_panics) { |
| ... | ... | @@ -33573,6 +33578,7 @@ fn analyzeSlice( |
| 33573 | 33578 | const sentinel = s: { |
| 33574 | 33579 | if (sentinel_opt != .none) { |
| 33575 | 33580 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 33581 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 33576 | 33582 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ |
| 33577 | 33583 | .needed_comptime_reason = "slice sentinel must be comptime-known", |
| 33578 | 33584 | }); |