Support `&slice[range]` syntax for re-slicing

de09a1373b28b7687d4bdf98a4be0fae79f7976c76120b147170564b0cb27cfc
This is the first part of a change to move to required `&` when
re-slicing.
Alexis Sellier committed ago 1 parent c8c83e2b
lib/std/lang/resolver.rad +20 -0
4753 4753
                    itemType: arrayInfo.item,
4754 4754
                    mutable: addr.mutable,
4755 4755
                    capacity: arrayInfo.length,
4756 4756
                });
4757 4757
                try setNodeType(self, addr.target, *alloc);
4758 +
4759 +
                return try setNodeType(self, node, *alloc);
4760 +
            }
4761 +
            if let case Type::Slice { item, mutable } = subjectTy {
4762 +
                if addr.mutable and not mutable {
4763 +
                    throw emitError(self, addr.target, ErrorKind::ImmutableBinding);
4764 +
                }
4765 +
                try checkSliceRangeIndices(self, range);
4766 +
                let sliceTy = Type::Slice {
4767 +
                    item,
4768 +
                    mutable: addr.mutable,
4769 +
                };
4770 +
                let alloc = allocType(self, sliceTy);
4771 +
                try setSliceRangeInfo(self, node, SliceRangeInfo {
4772 +
                    itemType: item,
4773 +
                    mutable: addr.mutable,
4774 +
                    capacity: nil,
4775 +
                });
4776 +
                try setNodeType(self, addr.target, *alloc);
4777 +
4758 4778
                return try setNodeType(self, node, *alloc);
4759 4779
            }
4760 4780
        }
4761 4781
    }
4762 4782
    // Derive a hint for the target type from the slice hint.
lib/std/lang/resolver/printer.rad +1 -1
466 466
            io::print("slice field unknown: '");
467 467
            io::print(name);
468 468
            io::print("'");
469 469
        }
470 470
        case super::ErrorKind::SliceRequiresAddress => {
471 -
            io::print("array slicing requires taking an address");
471 +
            io::print("slicing requires taking an address with '&'");
472 472
        }
473 473
        case super::ErrorKind::SliceRangeOutOfBounds => {
474 474
            io::print("slice bounds exceed array length");
475 475
        }
476 476
        case super::ErrorKind::UnexpectedReturn => {