luau-lang / luau

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

AstExprCalls in if conditions are incorrectly refined (new solver) #1528

Open checkraisefold opened 6 days ago

checkraisefold commented 6 days ago

Sample (usable in luau-lsp, though a basic ClassType or other type w/ a function taking self could repro):

--!strict
local RunService = game:GetService("RunService")
-- is RunService, not RunService?

if RunService:IsRunning() then
    local b = RunService
    -- b is RunService? instead of RunService
end
print(RunService)

Unsure if related to https://github.com/luau-lang/luau/issues/1517 Arguments (including the RunService as self here) are appended to returnRefinements, which has optional appended by https://github.com/luau-lang/luau/blob/e905e305702388543dac9040667968c0b856506d/Analysis/src/ConstraintGenerator.cpp#L611