Skip to content

Assignment of optional var to non-optional value should unwrap it. #24

Description

@tcard

This should work:

var x ?X
x = X{...}
// x has type X now

Right now you're forced to do this:

var x ?X
x = X{...}
if x != nil {
    // x has type X now
}

But the compiler could figure out that x is not nil there.

Be careful with this, though:

var x ?X
x = X{...}
// x has type X now
if something {
    x = nil
}
// x should have type ?X again now

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions