You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Returning a Copy element of an owned array parameter is refused as a view: fn arr(xs: [i32; 2]): xs[0] #2334
Expected: prints 7. The parameter owns the array; xs[0] is an i32 (Copy), and the inferred return is an owned i32.
Actual (installed compiler and D114 stage1 alike):
error: returned view may outlive its origin 'xs'
--> arrret.w:1:23
The inferred return type keeps the element view instead of materializing the Copy value at the return demand. Found while checking literal-argument shapes for D114 (#2327); not caused by it.
By design under D22. The D22 acceptance cells (promoted 2026-10-18) rule that an inferred return preserves a view: test/compile_errors/err_d22_inferred_return_preserves_view.w (fn find(map: &HashMap[i32, i32]): map.get(1).unwrap() infers &i32 and keeps its origin) and behav_d22_exact_carrier_contextual_copy.w ("inferred returns ... preserve references"). A view materializes its Copy value only where an owned demand is established, and an unannotated return establishes none; so fn arr(xs: [i32; 2]): xs[0] infers &i32 viewing the consumed xs, and the escape diagnostic is correct. The written -> i32 is the guardrail that names the copy. A fix that materialized it (branch issues-b) broke both cells and was reverted; the mixed join of a view return beside an owned return (#2325) is the owned value and is fixed there.
Activity
ehartford commentedon Oct 23, 2026
By design under D22. The D22 acceptance cells (promoted 2026-10-18) rule that an inferred return preserves a view:
test/compile_errors/err_d22_inferred_return_preserves_view.w(fn find(map: &HashMap[i32, i32]): map.get(1).unwrap()infers&i32and keeps its origin) andbehav_d22_exact_carrier_contextual_copy.w("inferred returns ... preserve references"). A view materializes its Copy value only where an owned demand is established, and an unannotated return establishes none; sofn arr(xs: [i32; 2]): xs[0]infers&i32viewing the consumedxs, and the escape diagnostic is correct. The written-> i32is the guardrail that names the copy. A fix that materialized it (branch issues-b) broke both cells and was reverted; the mixed join of a view return beside an owned return (#2325) is the owned value and is fixed there.Six fixes from the issue backlog: #2545, #2524, #2334, #2325, #2443, #…