Skip to content

Unannotated fn with an early return value falls off the end into T.default() instead of 'missing return' (§4.10, D43) #1494

Closed

Description

@ehartford

Found while testing D60; not changed by it. Reproduced on origin/main 5848ae9 (stage1):

fn f(p: bool):
    if p: return 5
    print("x")
fn main: print(f(false))

prints x then 0, no diagnostic. D43 infers i32 from return 5, and infer_unannotated_function_return_type (SemaCheck) then accepts the fall-off whenever the inferred type has a default (it only errors "return type does not implement Default").

§4.10: "If any path in the body explicitly returns a value (a return expr or a non-Unit tail expression on another branch), implicit default return does not apply — a function that demonstrably produces values elsewhere but falls off the end is reported as a missing return, not defaulted." D43: "a value on one path and fall-off on another remains §4.10's missing-return error." The annotated spelling (fn f(p: bool) -> i32:) is already "missing return" (the body_ty == ty_void branch of the declared-return check); the unannotated one substitutes i32.default().

Expected: "missing return" for the unannotated spelling too. Needs a sweep of unannotated functions that rely on it before landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions