In this example, bar inside the method is inferred to not be nil:
class Foo
property bar : String?
end
def test
foo = Foo.new
foo.bar = "bar"
unless (bar = foo.bar) && true # <--- !
return
end
p bar.reverse
end
test # => "rab"
In this one it's not:
class Foo
property bar : String?
end
def test
foo = Foo.new
foo.bar = "bar"
unless true && (bar = foo.bar) # <--- !
return
end
p bar.reverse
end
test # => undefined method 'reverse' for nil (compile-time type is (String | Nil))
Perhaps it's because the assignment of bar itself depends on the former condition being truthy, but I think the Nil type should be filtered out if the conditions hold.
Any progress on this? It's still reproducible on 0.25.1. If this is a long-term goal/plan, it should be labeled as such, or some project should be made to contain things like this.
This was fixed at some point so I'm closing it.
Most helpful comment
This was fixed at some point so I'm closing it.