| ... | ... | @@ -33285,15 +33285,34 @@ fn analyzeSlice( |
| 33285 | 33285 | } |
| 33286 | 33286 | |
| 33287 | 33287 | bounds_check: { |
| 33288 | | const actual_len = if (array_ty.zigTypeTag(mod) == .Array) |
| 33289 | | try mod.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(mod)) |
| 33290 | | else if (slice_ty.isSlice(mod)) l: { |
| 33291 | | const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice); |
| 33292 | | break :l if (slice_ty.sentinel(mod) == null) |
| 33293 | | slice_len_inst |
| 33294 | | else |
| 33295 | | try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true); |
| 33296 | | } else break :bounds_check; |
| 33288 | const actual_len = l: { |
| 33289 | if (array_ty.zigTypeTag(mod) == .Array) { |
| 33290 | const len = array_ty.arrayLenIncludingSentinel(mod); |
| 33291 | // If the end is comptime-known, we can emit a |
| 33292 | // compile error if it would be out-of-bounds even |
| 33293 | // with a start value of 0. |
| 33294 | if (uncasted_end_opt != .none) { |
| 33295 | if (try sema.resolveDefinedValue(block, end_src, uncasted_end_opt)) |end_val| { |
| 33296 | const end_int = end_val.getUnsignedInt(mod).?; |
| 33297 | if (end_int > len) return sema.fail( |
| 33298 | block, |
| 33299 | end_src, |
| 33300 | "slice end index {d} exceeds array length of type '{}'", |
| 33301 | .{ end_int, array_ty.fmt(mod) }, |
| 33302 | ); |
| 33303 | } |
| 33304 | } |
| 33305 | break :l try mod.intRef(Type.usize, len); |
| 33306 | } |
| 33307 | if (slice_ty.isSlice(mod)) { |
| 33308 | const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice); |
| 33309 | break :l if (slice_ty.sentinel(mod) == null) |
| 33310 | slice_len_inst |
| 33311 | else |
| 33312 | try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true); |
| 33313 | } |
| 33314 | break :bounds_check; |
| 33315 | }; |
| 33297 | 33316 | |
| 33298 | 33317 | const actual_end = if (slice_sentinel != null) |
| 33299 | 33318 | try sema.analyzeArithmetic(block, .add, end, .one, src, end_src, end_src, true) |