Open PennyJim opened 1 day ago
After some testing and reading the codebase, I think I have found the root cause:
{ ... }
currently won't infer integer
as one of the types of its key.The related logic is here: https://github.com/LuaLS/lua-language-server/blob/b815469b3df0655b59a8d2eae2770a3b85c98ad8/script/vm/sign.lua#L114-L117
AnyType
for tvalueNode
, it's returning nil
for tfieldNode
vm.getTableKey
: https://github.com/LuaLS/lua-language-server/blob/b815469b3df0655b59a8d2eae2770a3b85c98ad8/script/vm/type.lua#L711-L725tableexp
, i.e. t = { 1, 2, 3 }
, then it would consider integer
type for its keyI changed line 724 to include varargs
type
if field.type == 'tableexp' or field.type == 'varargs' then
=> then it works 🎉
maybe you can try open a PR on this after more testing 😄 @PennyJim
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
This is similar to #1355
When I try and itterate over a Vararg table, it'll be unable to determine the indexing value.
Actual Behaviour
My enabling of no-unknowns comes and bites me as the key is unknown.
Reproduction steps
Additional Notes
I've been told that there might be edge cases that are why this isn't how it currently works, but I thought I'd ask to at least find them out and learn more.
And if you are questioning why I'm using pairs instead of ipairs, that's because I'm modding in factorio with a deterministic pairs. It is actually faster than ipairs with functionally the same result, but with support for sparse arrays (this makes other Lua environments so sad to work with...).
Finally, I'm writing this at work in the morning before I forget, so I'm not being as thorough as I would prefer. I can absolutely get more information if requested.
Log File
No response