| ... | @@ -19741,6 +19741,14 @@ fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi | ... | @@ -19741,6 +19741,14 @@ fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi |
| 19741 | return sema.failWithExpectedOptionalType(block, src, ty); | 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 | fn zirIsNonNull( | 19752 | fn zirIsNonNull( |
| 19745 | sema: *Sema, | 19753 | sema: *Sema, |
| 19746 | block: *Block, | 19754 | block: *Block, |
| ... | @@ -20542,6 +20550,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20542,6 +20550,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20542 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ | 20550 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ |
| 20543 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", | 20551 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", |
| 20544 | }); | 20552 | }); |
| | 20553 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 20545 | break :blk val.toIntern(); | 20554 | break :blk val.toIntern(); |
| 20546 | } else .none; | 20555 | } else .none; |
| 20547 | | 20556 | |
| ... | @@ -28114,13 +28123,9 @@ fn panicSentinelMismatch( | ... | @@ -28114,13 +28123,9 @@ fn panicSentinelMismatch( |
| 28114 | .operation = .And, | 28123 | .operation = .And, |
| 28115 | } }, | 28124 | } }, |
| 28116 | }); | 28125 | }); |
| 28117 | } else if (sentinel_ty.isSelfComparable(zcu, true)) | 28126 | } else ok: { |
| 28118 | try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel) | 28127 | assert(sentinel_ty.isSelfComparable(zcu, true)); |
| 28119 | else { | 28128 | break :ok try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel); |
| 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; | | |
| 28124 | }; | 28129 | }; |
| 28125 | | 28130 | |
| 28126 | if (!pt.zcu.comp.formatted_panics) { | 28131 | if (!pt.zcu.comp.formatted_panics) { |
| ... | @@ -33573,6 +33578,7 @@ fn analyzeSlice( | ... | @@ -33573,6 +33578,7 @@ fn analyzeSlice( |
| 33573 | const sentinel = s: { | 33578 | const sentinel = s: { |
| 33574 | if (sentinel_opt != .none) { | 33579 | if (sentinel_opt != .none) { |
| 33575 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); | 33580 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| | 33581 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 33576 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ | 33582 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ |
| 33577 | .needed_comptime_reason = "slice sentinel must be comptime-known", | 33583 | .needed_comptime_reason = "slice sentinel must be comptime-known", |
| 33578 | }); | 33584 | }); |