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 closure does not capture a local used inside a .Variant(args) shorthand — () => .Some(n) reads 0/null (§12.4) #1570
Found by the closure cells added to tools/drop_audit.w for #1486 (run_unit(() => a = .Some(mk(2, slot))) passed mk a null slot and crashed in R.drop).
check_closure collects captures with expr_uses_symbol(body, sym), and that walk does not descend into the arguments of an NK_VARIANT_SHORTHAND (.Some(n)). The symbol is not captured, the closure environment has no slot for it, and MirLower lowers the use to a zero constant. The explicit spelling Some(n) is captured correctly.
Reproduces on the installed compiler (v0.15.2.1) and a stage1 of origin/main f1e3bd2:
No diagnostic. §12.4: a closure captures the variables its body uses; a .Variant(args) argument is an ordinary expression (#933 made Sema check those arguments against the payload types, but the capture walk was not updated). A raw-pointer capture (slot: *mut i32) becomes null the same way, which is how it surfaced as a segfault.
Workaround in the audit cell: spell Some(...); the fix can restore .Some(...).
Activity
Closures: a drop of a by-place capture frees the captured place, not …
Codegen: a drop of a by-place closure capture frees the captured plac…
Codegen: a drop of a by-place closure capture frees the captured plac…
Codegen: a drop of a by-place closure capture frees the captured plac…
Closures: every capture is found, a stored view is refused, a call th…
Sema: a type in expression position names no value — transmute[T](x) …
Modeled-C Amendment 2 (D76): callback argv/user data without unsafe (#…