P5-0: M/C regression on p4-frozen (6/6 PASS); fix frontend defect A found by gate R3

A `ref` of a place reached through a `mut` borrow (`ref s.buf`, `ref s.n`
with `s: mut<S>`) is now a shared reborrow (borrow.ref). Before, an array
field lowered to slice_mut and reached the verifier as E1001, and a scalar
field was rejected with E7005. Regression test ref_through_mut.aji.
This commit is contained in:
dev committed 2026-10-06 00:35:22 +03:00
1 parent 2bbbd2135c
commit cfee89ff19
4 files changed
+147 -1

No files matched your search

+7
View File
@@ -1863,6 +1863,13 @@ const Lowerer = struct {
/// returned as is (`ends` empty).
fn placeBorrow(l: *Lowerer, place: ast.Expr, mutable: bool, want_slice: bool, span: Span) Error!Placed {
var p = try l.placeRaw(place, mutable, span);
// `ref place` reached through a `mut` borrow (`ref s.buf` with
// `s: mut<S>`) is a shared reborrow of it (spec 07a `borrow.ref`).
if (want_slice and !mutable and (p.v.ty == .mut or p.v.ty == .slice_mut)) {
const t = if (p.v.ty == .mut) try l.wrap(.ref, p.v.ty.inner().?) else try l.wrap(.slice, p.v.ty.inner().?);
const r = try l.def("r", t, try l.fmt("borrow.ref %{s}", .{p.v.name}), span);
p = .{ .v = r, .ends = try l.concat(p.ends, r.name) };
}
if (want_slice and (p.v.ty == .ref or p.v.ty == .mut) and p.v.ty.inner().? == .array) {
const elem = p.v.ty.inner().?.array.elem;
const sl = try l.def("s", (if (mutable) try l.wrap(.slice_mut, elem) else try l.wrap(.slice, elem)), try l.fmt("slice.make %{s}", .{p.v.name}), span);