sgo icon indicating copy to clipboard operation
sgo copied to clipboard

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

Open tcard opened this issue 8 years ago • 0 comments

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

tcard avatar Aug 07 '16 20:08 tcard