| ... | @@ -32160,6 +32160,30 @@ fn analyzeSlice( | ... | @@ -32160,6 +32160,30 @@ fn analyzeSlice( |
| 32160 | if (!end_is_len) { | 32160 | if (!end_is_len) { |
| 32161 | const end = if (by_length) end: { | 32161 | const end = if (by_length) end: { |
| 32162 | const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); | 32162 | const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| | 32163 | if (try sema.resolveValue(len)) |slice_len_val| { |
| | 32164 | const len_s_val = try mod.intValue( |
| | 32165 | Type.usize, |
| | 32166 | array_ty.arrayLenIncludingSentinel(mod), |
| | 32167 | ); |
| | 32168 | if (!(try sema.compareScalar(slice_len_val, .lte, len_s_val, Type.usize))) { |
| | 32169 | const sentinel_label: []const u8 = if (array_ty.sentinel(mod) != null) |
| | 32170 | " +1 (sentinel)" |
| | 32171 | else |
| | 32172 | ""; |
| | 32173 | |
| | 32174 | return sema.fail( |
| | 32175 | block, |
| | 32176 | end_src, |
| | 32177 | "length {} out of bounds for array of length {}{s}", |
| | 32178 | .{ |
| | 32179 | slice_len_val.fmtValue(Type.usize, mod), |
| | 32180 | len_val.fmtValue(Type.usize, mod), |
| | 32181 | sentinel_label, |
| | 32182 | }, |
| | 32183 | ); |
| | 32184 | } |
| | 32185 | } |
| | 32186 | // check len is less than array size if comptime known |
| 32163 | const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false); | 32187 | const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false); |
| 32164 | break :end try sema.coerce(block, Type.usize, uncasted_end, end_src); | 32188 | break :end try sema.coerce(block, Type.usize, uncasted_end, end_src); |
| 32165 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); | 32189 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |