Skip to content

Invalid fields injected warning #2341

Description

@sewbacca

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?

Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

No warning.

Actual Behaviour

Fields cannot be injected into the reference of `AClass` for `a`. To do so, use `---@class` for `o`.Lua Diagnostics.(inject-field)

grafik

Reproduction steps

local function new()
	---@class AClass
	local obj = {
		a = 1
	}
	obj.b = 2
	return obj
end

local o = new()

o.a = 2 -- This gives a warning
o.b = 3

Additional Notes

When initializing a class with a table constructor, the used fields are no longer mutable, they seem to be semi existent. Existent enough for autocompletion and usage, but not for modifications.

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions