Skip to content

Commit 7f76050

Browse files
authored
Merge pull request #2991 from tomlau10/bugfix/function_array
fix: incorrect infer of function array annotation on tables
2 parents 108ce76 + 2918ceb commit 7f76050

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5+
* `FIX` Incorrect infer for function array annotation on tables [#2367](https://github.com/LuaLS/lua-language-server/issues/2367)
56

67
## 3.13.4
78
`2024-12-13`

script/parser/guide.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ local assignTypeMap = {
940940
['setindex'] = true,
941941
['tablefield'] = true,
942942
['tableindex'] = true,
943+
['tableexp'] = true,
943944
['label'] = true,
944945
['doc.class'] = true,
945946
['doc.alias'] = true,

script/vm/compiler.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,9 @@ local compilerSwitch = util.switch()
16711671
vm.compileByParentNode(source.node, key, function (src)
16721672
if src.type == 'doc.field'
16731673
or src.type == 'doc.type.field'
1674-
or src.type == 'doc.type.name' then
1674+
or src.type == 'doc.type.name'
1675+
or src.type == 'doc.type.function'
1676+
then
16751677
hasMarkDoc = true
16761678
vm.setNode(source, vm.compileNode(src))
16771679
end

test/type_inference/common.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,34 @@ TEST 'number' [[
39433943
local function f(<?x?>) end
39443944
]]
39453945

3946+
TEST 'number' [[
3947+
---@type fun(x:number)[]
3948+
local t = {
3949+
function (<?x?>) end,
3950+
}
3951+
]]
3952+
3953+
TEST 'number' [[
3954+
---@type fun(x:number)[]
3955+
local t = {
3956+
[1] = function (<?x?>) end,
3957+
}
3958+
]]
3959+
3960+
TEST 'number' [[
3961+
---@type {[integer]: fun(x:number)}
3962+
local t = {
3963+
function (<?x?>) end,
3964+
}
3965+
]]
3966+
3967+
TEST 'number' [[
3968+
---@type {[integer]: fun(x:number)}
3969+
local t = {
3970+
[1] = function (<?x?>) end,
3971+
}
3972+
]]
3973+
39463974
TEST 'boolean' [[
39473975
---@generic T: string | boolean | table
39483976
---@param x T

0 commit comments

Comments
 (0)