Skip to content

A non-Unit tail under -> Never passes Sema and fails the MIR validator (wrong layer) #1493

Closed

Description

@ehartford

Found while testing D60 (fn f -> Never: g = 1, which now yields a read of g and takes this path). Reproduced on origin/main 5848ae9 (stage1):

fn f -> Never: 5
fn main: f()
error: invalid MIR before codegen: use rvalue type is incompatible with assign destination (dest ty=15 kind=18, src ty=3 kind=1)
 --> never5.w:1:17

The block spelling (let a = 1 then g) is the same. Sema accepts an i32 tail under a declared Never return; the MIR validator catches it, so it is loud, but the diagnostic is a compiler-internal one at the wrong layer. Expected: Sema's "return type mismatch" at the tail (a Never function's body must diverge on every path). The branch in check_fn_body_with_sig_at that compares a non-Unit tail against the declared return (types_compatible / implicit Ok wrapping) lets it through.

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