check return expressions against the enclosing function's return type #78
Loading…
Reference in a new issue
No description provided.
Delete branch "us59/check-return-against-fn-return-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #59.
Extends #3's return-type checking to early
returns, not just a function body's trailing expression.Scope::current_fn_return: Option<Ty<'db>>, set bycheck_fnbefore checking the body and restored to its previous value right after - a save/restore around the body check (not a stack), so Rust's own call stack naturally handlesfn-nested-in-fncorrectly and non-nested functions never see a leaked value.check_returnhandlesExpr::Return's optional value:return xis checked againstcurrent_fn_return, barereturnis checked againstTy::unit(db), reusingDiagnosticKind::ReturnTypeMismatch/NoTypeProducedrather than adding new diagnostic variants.check_fn's-> typecarve-out (a function declared-> typeaccepts any concrete type areturnproduces).returnoutside any function (current_fn_returnunset) is deferred, same policy asbreakoutside a loop.New tests cover matching/mismatched value and bare-return cases, the outside-a-function case, the
-> typecarve-out, and a return value that itself fails to type-check.