luau-lang / luau

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

Magic functions are not called for overloaded function types (new solver) #1447

Open checkraisefold opened 4 weeks ago

checkraisefold commented 4 weeks ago

Upon analysis of a luau-lsp failing test for the new solver, it was discovered that for overloaded table/class function properties using an IntersectionType, magic functions are never called.

This is because the overloaded type is only resolved after the magic functions are attempted to be called. See here: https://github.com/luau-lang/luau/blob/master/Analysis/src/ConstraintSolver.cpp#L1209-L1216 (where ftv will be invalid, because it is an IntersectionType) https://github.com/luau-lang/luau/blob/master/Analysis/src/ConstraintSolver.cpp#L1244-L1260 (the code immediately afterwards, with a valid function type)

Unfortunately, I don't think theres a workaround from luau-lsp's side for now; so this is the only blocker compared to the old solver as of yet on that side of things.

checkraisefold commented 1 day ago

After looking at how Studio behaves with the WaitForChild type, I came up with pretty identical behavior using a magic function to make the instance type optional when timeout argument is present instead of using an overload through an IntersectionType as a workaround.