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
Bug: a labeled statement drops the function's implicit tail-expression return value (§29.13/§13.5b) #640
When a function body contains a 'label: statement, the function's implicit tail expression is no longer returned — the function returns the type's default (empty string / 0) instead. An explicit return works. The label need not be used (an unused-label warning is emitted), and it need not sit on the tail expression itself — any labeled statement in the body triggers it.
Repro
fn f() -> i32:
let s = 42
'done:
s // tail expression
fn main:
print(f"[{f()}]") // prints [0] — want [42]
fn g() -> str:
let s = "hello"
'done:
"v=" ++ s // tail expression
// f() returns "" — want "v=hello"
Both print empty/zero. Replacing the tail with return s / return "v=" ++ s yields the correct value, and goto 'done targeting the label + an explicit return after it also works (verified: [start!]/[nojump!]). So the defect is specifically implicit tail return in a body that contains a labeled statement.
Spec
§29.13 block body / implicit return (the last expression of a block is its value) interacting with §13.5b labels/goto. A labeled statement must not change whether the block's final expression is the block's value.
Impact / discovery
Found writing the §23.3 goto-through-with coverage (#536). Blocks the tail-expression form of any goto-to-forward-label pattern; the #536 goto fixtures must use explicit return as a workaround until this is fixed. Orthogonal to with — reproduces with no with block.
Root-cause direction
Block-tail detection / lowering treats the final expression as statement-position (value discarded) once a NK-label statement is present in the block, so no tail value is propagated as the return. Likely in the block-lowering path that identifies the trailing expression (MirLower block/tail handling) — the label statement shifts or masks the tail slot.
Fixed in 6cfddb7. A labeled block in tail position now yields its tail value (was the type default). One MIR site: lower_block_mode materialized the labeled block's tail value instead of returning unit. The type side was already correct. Self-host flip sweep clean by construction — src/lib/build have zero labeled statements; fixpoint held. Verified: int/str tails, goto-to-forward-label + tail, non-Copy Drop tail (drops exactly once). 4 fixtures.
Activity
Fix #641a/#641b/#642: mut-self borrows (incl. Drop types); explicit .…
ehartford commentedon Jul 5, 2026
Fixed in 6cfddb7. A labeled block in tail position now yields its tail value (was the type default). One MIR site: lower_block_mode materialized the labeled block's tail value instead of returning unit. The type side was already correct. Self-host flip sweep clean by construction — src/lib/build have zero labeled statements; fixpoint held. Verified: int/str tails, goto-to-forward-label + tail, non-Copy Drop tail (drops exactly once). 4 fixtures.
Fix #640: a labeled block in tail position yields its tail value (§29…
Tests: retire stale #640 workaround comment