lua-language-server
lua-language-server copied to clipboard
assign-type-mismatch not reported for global values
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Annotations, Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
With a global table that has type-annotated fields, reassigning a field to an incorrectly-typed value should report [assign-type-mismatch]
Actual Behaviour
No diagnostic is reported, even though autocompletion indicates that the type is understood by the server. Further, assigning a local variable to the global value and doing the same thing does report the diagnostic correctly.
Reproduction steps
---@class test
_G.test = {
---@type boolean
foo = true,
}
test.foo = 'bar' -- no error
_G.test.foo = 'bar' -- no error
local test2 = test
test2.foo = 'bar' -- [assign-type-mismatch]
Additional Notes
No response
Log File
No response
This is because the global variables have been specially optimized at present, so the rigor of some type systems has been lost. This optimization is for many large projects that abuse global variables. We may need to switch this optimization on and off through a setting.
yes I noticed that too ;_;
Ran into this myself. For projects that don't abuse globals, a switch to disable it would be much appreciated.
I'm also facing this problem in my current project, Solution to this will be appreciated.