LuaLS / LuaLS/lua-language-server
Error "Undefined field" on _G if global is declared by Lua.diagnostics.globals
Nobody has claimed this yet.
- 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?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
Linux
### What is the issue affecting?
Diagnostics/Syntax Checking
### Expected Behaviour
``` lua
local extract0 = bit32 and bit32.extract -- Lua 5.2/Lua 5.3 in compatibility mode
local extract = _G.bit32 and _G.bit32.extract -- Lua 5.2/Lua 5.3 in compatibility mode
```
Expected: No error
### Actual Behaviour
Error on 2nd line:
> (global) _G.bit32: unknown
> Undefined field `bit32`.Lua Diagnostics.(undefined-field)
### Reproduction steps
1. Add 'bit32' to globals;
2. Errors on 1st line disappeared; but errors on 2nd line persists.
### Additional Notes
> sumneko.lua-3.6.18-linux-x64
Real global variables does not trigger errors. Only Lua.diagnostics.globals items lead to errors.
Additional question: how to mute errors for this pattern?
``` lua
if _G.bit then -- LuaJIT
local shl, shr, band = _G.bit.lshift, _G.bit.rshift, _G.bit.band
...
end
```
```@diagnostic disable:``` mute too much, but ```@diagnostic disable-line:``` mute too little.
### Log File
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostics issue in the Visual Studio Code extension using Lua.diagnostics.globals with bit32, comparing direct access with _G.bit32 access. Trace the diagnostics handling for configured globals; done means _G.bit32 no longer reports an undefined field while unrelated undefined-field diagnostics and line-level suppression behavior remain intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100