diff --git a/changelog.md b/changelog.md index 51c327dbb..d1d0d1088 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Incorrect infer for function array annotation on tables [#2367](https://github.com/LuaLS/lua-language-server/issues/2367) ## 3.13.4 `2024-12-13` diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 429785125..0c9347f8d 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -940,6 +940,7 @@ local assignTypeMap = { ['setindex'] = true, ['tablefield'] = true, ['tableindex'] = true, + ['tableexp'] = true, ['label'] = true, ['doc.class'] = true, ['doc.alias'] = true, diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 55406da68..92da538e5 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1671,7 +1671,9 @@ local compilerSwitch = util.switch() vm.compileByParentNode(source.node, key, function (src) if src.type == 'doc.field' or src.type == 'doc.type.field' - or src.type == 'doc.type.name' then + or src.type == 'doc.type.name' + or src.type == 'doc.type.function' + then hasMarkDoc = true vm.setNode(source, vm.compileNode(src)) end diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua index 58369b992..4140e2b01 100644 --- a/test/type_inference/common.lua +++ b/test/type_inference/common.lua @@ -3943,6 +3943,34 @@ TEST 'number' [[ local function f() end ]] +TEST 'number' [[ +---@type fun(x:number)[] +local t = { + function () end, +} +]] + +TEST 'number' [[ +---@type fun(x:number)[] +local t = { + [1] = function () end, +} +]] + +TEST 'number' [[ +---@type {[integer]: fun(x:number)} +local t = { + function () end, +} +]] + +TEST 'number' [[ +---@type {[integer]: fun(x:number)} +local t = { + [1] = function () end, +} +]] + TEST 'boolean' [[ ---@generic T: string | boolean | table ---@param x T