lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

assign-type-mismatch not reported for global values

Open mcwhitfield opened this issue 2 years ago • 4 comments

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

mcwhitfield avatar Dec 24 '22 18:12 mcwhitfield

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.

sumneko avatar Jan 16 '23 10:01 sumneko

yes I noticed that too ;_;

dganzella avatar Aug 08 '23 13:08 dganzella

Ran into this myself. For projects that don't abuse globals, a switch to disable it would be much appreciated.

jtackaberry avatar Oct 11 '23 00:10 jtackaberry

I'm also facing this problem in my current project, Solution to this will be appreciated.

jharajeev55 avatar May 09 '24 13:05 jharajeev55