Skip to content

Calling an empty closure crashes with no message (a null fn, or a fn? holding null) #3091

Closed

Description

@nicolas-maman

Calling an empty closure crashes with no message.

main() {
    let c: fn = null
    c()
    println("after")
}

Program crashed (0xC0000005: access violation) (v0.838.0): null is the empty closure (#3062, and since #3077 in every closure slot, an optional's included), and a call through it jumps to address 0. A fn? given null is present (some empty closure), so o ?? || { ... } keeps it and the call crashes the same way.

Expected: a call through an empty closure is a named panic at the call site ("called an empty closure"), as other runtime errors are, so the program says what went wrong and where. The fn?/null reading belongs in the language reference beside it: null in a fn? is a present empty closure, none is the absence.

Found reviewing #3077 on #3085.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions