Skip to content

duplicate-set-field diagnostic when assigning a function to a table field #2551

Open

Description

@urnati

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

No diagnostic warning on assignment because the variable has been 'cleared'.

Actual Behaviour

The two info.func assignments that are "= function" get a Duplicate field 'func' (duplicate-set-field) diagnostic.
The info.func assignment "= l1" does not.
Scope depth does not seem to impact the diagnostic - within the same function.

Assignments to other fields that are string, integer, etc do not get the diagnostic.
FYI - the ".func" is expected in a library I cannot change.

Reproduction steps

local function l1()
end
local function f1()
local info = {};
do
info = {};
info.notCheckable = true
info.func = function()
-- any code
end
end
info = {};
info.notCheckable = true
info.func = function()
-- any code
end
info = {};
info.notCheckable = true
info.func = l1
end

Additional Notes

No response

Log File

No response

Activity

  1. pearagit commented on Apr 5, 2024

    @pearagit

    chiming in that I also experience this

  2. serialnumbers commented on Oct 24, 2026

    @serialnumbers

    I hit a related case with the official LÖVE addon installed through the VS Code addon manager (Lua extension 3.19.2). The addon library declares the callback as an API stub (function love.load(arg, unfilteredArg) end in library/love.lua), and a normal project implementation such as function love.load() ... end is then reported as Duplicate field "load" (duplicate-set-field). This is not a duplicate at runtime: the addon declaration is metadata/API information, while the project function implements the LÖVE callback. The same issue applies to callbacks such as love.draw/love.update. It appears the diagnostic is treating the metadata stub as a conflicting project definition. Workaround is disabling duplicate-set-field, but that suppresses useful warnings workspace-wide. Could meta/addon definitions be excluded when checking duplicate field assignments, or callback override/implementation be recognized?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions