diff --git a/script/core/diagnostics/inject-field.lua b/script/core/diagnostics/inject-field.lua index 139b86364..570ca270a 100644 --- a/script/core/diagnostics/inject-field.lua +++ b/script/core/diagnostics/inject-field.lua @@ -50,6 +50,9 @@ return function (uri, callback) if def.type == 'doc.type.field' then return end + if def.type == 'doc.field' then + return + end end local howToFix = lang.script('DIAG_INJECT_FIELD_FIX_CLASS', { diff --git a/test/diagnostics/inject-field.lua b/test/diagnostics/inject-field.lua index 2c8022704..f4d847e9f 100644 --- a/test/diagnostics/inject-field.lua +++ b/test/diagnostics/inject-field.lua @@ -39,3 +39,26 @@ local m m.xx = 1 -- OK m.yy = 1 -- OK ]] + +TEST [[ +---@class Class +---@field x number + +---@type Class +local t + +t.x = 1 -- OK +t. = 2 -- Warning +]] + +TEST [[ +---@class Class +---@field x number +---@field [any] any + +---@type Class +local t + +t.x = 1 -- OK +t.y = 2 -- OK +]]