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
Sema: a view into a temporary escapes its statement silently — let p = args().get(1) reads as "" instead of being rejected #962
use std.process
let p = args().get(1)
print(f"view-into-temporary=<{p}> len={p.len()}")
$ with run tmpview.w HELLO
view-into-temporary=<> len=0
Binding the Vec first (let a = args() then a.get(1)) prints HELLO. Under WITH_DEBUG_ALLOC=1 the run reports no leak and no use-after-free, so the freed buffer is not touched: the view is an empty {ptr, len} rather than a dangling one (the runtime's arg vector materialization returns a temporary whose element view is taken and the temporary dropped at end of statement; the observed value is the zeroed slot).
Why it is a bug
D27: xs.get(i) returns &T, a view borrowing xs. Here xs is a temporary that dies at the end of the let, so the view has no living origin. §5.4 (ephemeral views) and §3.4 (returned references carry their origin) make this a compile-time rejection — "view may outlive its origin" is exactly the diagnostic the checker emits for a local that dies; a temporary is the shortest-lived local of all. Instead the program compiles, runs, and yields an empty string, which is the silent-fallback class CLAUDE.md forbids. It cost a real hour today: a with run rewrite script read its target path this way, found nothing to rewrite, and panicked with an empty path in the message.
Expected
with check (and run/build) reject it: "view into a temporary cannot outlive the statement; bind the value first" with the D27 hint (let argv = args()). Origin tracking already distinguishes locals from temporaries for check_returned_view_origins; the same origin must be stamped on element views of a temporary receiver at let initialization.
Found while auditing one-liners (docs/improve_oneliners.md, 2026-09-03).
Activity
A view into a statement temporary cannot be bound or returned (#962) (#…
Sema: an implicit drop writes every global its type's Drop impls writ…
Globals: a call, dyn dispatch, stored callable or drop that writes a …
Sema: a call whose result views a statement temporary is a view into …
Sema: corpus-private std modules (#2248); str.trim() is a view, the e…
Sema: a view into a parenthesized temporary is refused like any other (…
Sema: a binding or inferred return of a view into a statement tempora…
Sema: a binding or inferred return of a view into a statement tempora…