| ... | ... | @@ -31876,6 +31876,38 @@ fn analyzeSlice( |
| 31876 | 31876 | break :e try sema.coerce(block, .usize, uncasted_end, end_src); |
| 31877 | 31877 | } else break :e try sema.coerce(block, .usize, uncasted_end_opt, end_src); |
| 31878 | 31878 | } |
| 31879 | |
| 31880 | // when slicing a many-item pointer, if a sentinel `S` is provided as in `ptr[a.. :S]`, it |
| 31881 | // must match the sentinel of `@TypeOf(ptr)`. |
| 31882 | sentinel_check: { |
| 31883 | if (sentinel_opt == .none) break :sentinel_check; |
| 31884 | const provided = provided: { |
| 31885 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 31886 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 31887 | break :provided try sema.resolveConstDefinedValue( |
| 31888 | block, |
| 31889 | sentinel_src, |
| 31890 | casted, |
| 31891 | .{ .simple = .slice_sentinel }, |
| 31892 | ); |
| 31893 | }; |
| 31894 | |
| 31895 | if (ptr_sentinel) |current| { |
| 31896 | if (provided.toIntern() == current.toIntern()) break :sentinel_check; |
| 31897 | } |
| 31898 | |
| 31899 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 31900 | const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{}); |
| 31901 | errdefer msg.destroy(sema.gpa); |
| 31902 | if (ptr_sentinel) |current| { |
| 31903 | try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(pt), provided.fmtValue(pt) }); |
| 31904 | } else { |
| 31905 | try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(pt)}); |
| 31906 | } |
| 31907 | try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{}); |
| 31908 | break :msg msg; |
| 31909 | }); |
| 31910 | } |
| 31879 | 31911 | return sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src); |
| 31880 | 31912 | }; |
| 31881 | 31913 | |