| ... | @@ -32572,14 +32572,86 @@ fn analyzeSlice( | ... | @@ -32572,14 +32572,86 @@ fn analyzeSlice( |
| 32572 | .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) { | 32572 | .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) { |
| 32573 | .One => { | 32573 | .One => { |
| 32574 | const double_child_ty = ptr_ptr_child_ty.childType(mod); | 32574 | const double_child_ty = ptr_ptr_child_ty.childType(mod); |
| | 32575 | ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src); |
| 32575 | if (double_child_ty.zigTypeTag(mod) == .Array) { | 32576 | if (double_child_ty.zigTypeTag(mod) == .Array) { |
| 32576 | ptr_sentinel = double_child_ty.sentinel(mod); | 32577 | ptr_sentinel = double_child_ty.sentinel(mod); |
| 32577 | ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src); | | |
| 32578 | slice_ty = ptr_ptr_child_ty; | 32578 | slice_ty = ptr_ptr_child_ty; |
| 32579 | array_ty = double_child_ty; | 32579 | array_ty = double_child_ty; |
| 32580 | elem_ty = double_child_ty.childType(mod); | 32580 | elem_ty = double_child_ty.childType(mod); |
| 32581 | } else { | 32581 | } else { |
| 32582 | return sema.fail(block, src, "slice of single-item pointer", .{}); | 32582 | const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]"; |
| | 32583 | if (uncasted_end_opt == .none) { |
| | 32584 | return sema.fail(block, src, bounds_error_message, .{}); |
| | 32585 | } |
| | 32586 | const start_value = try sema.resolveConstDefinedValue( |
| | 32587 | block, |
| | 32588 | start_src, |
| | 32589 | uncasted_start, |
| | 32590 | .{ .needed_comptime_reason = bounds_error_message }, |
| | 32591 | ); |
| | 32592 | |
| | 32593 | const end_value = try sema.resolveConstDefinedValue( |
| | 32594 | block, |
| | 32595 | end_src, |
| | 32596 | uncasted_end_opt, |
| | 32597 | .{ .needed_comptime_reason = bounds_error_message }, |
| | 32598 | ); |
| | 32599 | |
| | 32600 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { |
| | 32601 | if (try sema.compareScalar(start_value, .neq, InternPool.Index.zero.toValue(), Type.comptime_int)) { |
| | 32602 | const err_msg = try sema.errMsg(block, start_src, bounds_error_message, .{}); |
| | 32603 | try sema.errNote( |
| | 32604 | block, |
| | 32605 | start_src, |
| | 32606 | err_msg, |
| | 32607 | "expected '{}', found '{}'", |
| | 32608 | .{ |
| | 32609 | Value.zero_comptime_int.fmtValue(Type.comptime_int, mod), |
| | 32610 | start_value.fmtValue(Type.comptime_int, mod), |
| | 32611 | }, |
| | 32612 | ); |
| | 32613 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| | 32614 | } else if (try sema.compareScalar(end_value, .neq, InternPool.Index.one.toValue(), Type.comptime_int)) { |
| | 32615 | const err_msg = try sema.errMsg(block, end_src, bounds_error_message, .{}); |
| | 32616 | try sema.errNote( |
| | 32617 | block, |
| | 32618 | end_src, |
| | 32619 | err_msg, |
| | 32620 | "expected '{}', found '{}'", |
| | 32621 | .{ |
| | 32622 | Value.one_comptime_int.fmtValue(Type.comptime_int, mod), |
| | 32623 | end_value.fmtValue(Type.comptime_int, mod), |
| | 32624 | }, |
| | 32625 | ); |
| | 32626 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| | 32627 | } |
| | 32628 | } else { |
| | 32629 | if (try sema.compareScalar(end_value, .gt, InternPool.Index.one.toValue(), Type.comptime_int)) { |
| | 32630 | return sema.fail( |
| | 32631 | block, |
| | 32632 | end_src, |
| | 32633 | "end index {} out of bounds for slice of single-item pointer", |
| | 32634 | .{end_value.fmtValue(Type.comptime_int, mod)}, |
| | 32635 | ); |
| | 32636 | } |
| | 32637 | } |
| | 32638 | |
| | 32639 | array_ty = try mod.arrayType(.{ |
| | 32640 | .len = 1, |
| | 32641 | .child = double_child_ty.toIntern(), |
| | 32642 | }); |
| | 32643 | const ptr_info = ptr_ptr_child_ty.ptrInfo(mod); |
| | 32644 | slice_ty = try mod.ptrType(.{ |
| | 32645 | .child = array_ty.toIntern(), |
| | 32646 | .flags = .{ |
| | 32647 | .alignment = ptr_info.flags.alignment, |
| | 32648 | .is_const = ptr_info.flags.is_const, |
| | 32649 | .is_allowzero = ptr_info.flags.is_allowzero, |
| | 32650 | .is_volatile = ptr_info.flags.is_volatile, |
| | 32651 | .address_space = ptr_info.flags.address_space, |
| | 32652 | }, |
| | 32653 | }); |
| | 32654 | elem_ty = double_child_ty; |
| 32583 | } | 32655 | } |
| 32584 | }, | 32656 | }, |
| 32585 | .Many, .C => { | 32657 | .Many, .C => { |