Skip to content

Error "Undefined field" on _G if global is declared by Lua.diagnostics.globalsΒ #2064

@myocytebd

Description

@myocytebd

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

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?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions