luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau-lang.org
MIT License
3.8k stars 352 forks source link

Autocomplete stops solving table.property because of "if table.property then return end", within a function body #1191

Closed karl-police closed 3 months ago

karl-police commented 3 months ago
local tbl = {}
tbl.Property = nil :: string?

function test()
    if tbl.Property then
        return
    end

    tbl.Property.

end

image

The autocomplete breaks because there's return

Expected result would be

image

 

 

This doesn't happen for image

 

It does know what type it is though. image

AmaranthineCodices commented 3 months ago

This is working as intended.

Luau has observed the control flow in the if statement and determined that at the point that you're typing tbl.Property, it must be nil due to the original type annotation of string?. As such, there are no autocomplete suggestions being presented here.

karl-police commented 3 months ago

This is working as intended.

Luau has observed the control flow in the if statement and determined that at the point that you're typing tbl.Property, it must be nil due to the original type annotation of string?. As such, there are no autocomplete suggestions being presented here.

hmm yeah

usually functions where you use return over assert, are a bit meh... because the autocomplete takes the first "return" argument of a function, so it returns nil if the first condition resolves into true, or it actually just skips through it