-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overloaded methods do not properly return a generic bound to the self parameter #3087
Comments
Hi, I am the author of #2898 and #2765 (though I am not author of LuaLS). This is a very detailed bug report 👍 It's been a while since I wrote those fix PRs. PR #2765This tries to fix #2758, where the infer on functions with overloads are inconsistent.
run time error in #2776
The regression fix
Seems we need to find out why the run time error fix in 8ecec08 (3.10.1) is problematic 🤔 |
known facts
the overly complicated fix in 8ecec088ecec08 is the runtime error fix to #2776. I reinvestigated #2776, the root cause seems to be that:
the fix
if call.args then
-- recompile existing node caches of args to allow recomputation with the type narrowed call
for _, arg in ipairs(call.args) do
if vm.getNode(arg) then
vm.removeNode(arg)
vm.compileNode(arg)
end
end
end This seems passed all existing tests, as well as the reproduction snippet in your example 😄 |
Gonna be honest, I might have confused 2765 with another PR, that's my bad. I did actually look into what was causing this but LuaLS is a complex beast and I couldn't find anything that would lead to the solution, so I'm glad you found something. Thanks for looking into this so quickly. |
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking
Expected Behaviour
Given the following code:
The following should be true:
All three local variables should be the
B
type as that is what genericS
would be during this method call.Actual Behaviour
The following is given instead by LuaLS:
From my testing, it seems that given any amount of overloads and a method call the following seems to happen. Whether this is actually what happens in LuaLS is a different story as I could not figure out why this happens.
any
sB:method1("str")
-->B:method1(any)
B:method1(any)
matchesA:method1(str: string)
B:method1(any)
matchesA:method1(num1: number, num2?: number, num3?: number)
unknown
instead.Reproduction steps
(Alternatively, use the test cases file found in the "Additional Notes" section)
x
,y
, andz
.x
andy
have the wrong type while localz
is fine.Additional Notes
This method of returning
self
is being done because theself
keyword does not actually resolve to the class being used for the method call and always seems to be class that created the method instead.This error started appearing in 3.10.1 and has not been fixed yet as of 3.13.6.

(The testing was done before 3.13.6 was released and I have personally tested 3.13.6 and confirm that it is still the same as 3.13.5)
The following file was used to get the information for the above chart.
testcases.txt
Reverting the changes made by #2898 and #2765 appears to fix this issue (while also re-introducing the bugs those PRs fixed.)
I have searched for other issues related to this, but only found mostly unrelated issues. However, i did find one comment on issue #723 that mentions this exact bug and the PR following it (#2898) seemed to only fix half of the issue. (As shown by version 3.12.0 correcting more than half of the test cases in the test case file.)
Log File
file_d%3A__test.log
The text was updated successfully, but these errors were encountered: