LuaLS / LuaLS/lua-language-server

assign-type-mismatch not reported for global values

Open
#1,781 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### 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

```lua
---@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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Lua reproduction and compare diagnostics for test.foo, _G.test.foo, and test2.foo. Trace the type-checking and diagnostics path for global values; done means the two global assignments report [assign-type-mismatch] consistently with the local alias case.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.