Skip to content

Commit c69e65f

Browse files
committed
infer types of tableindex by semantic
fix #1831
1 parent 02f6831 commit c69e65f

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# changelog
22

3+
## 3.6.8
4+
* `FIX` [#1831]
5+
[#1831]: https://github.com./sumneko/lua-language-server/issues/1831
6+
37
## 3.6.7
48
`2023-1-20`
59
* `FIX` [#1810]

script/vm/compiler.lua

+12
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,18 @@ local compilerSwitch = util.switch()
13251325
end
13261326
end
13271327

1328+
if not hasMarkDoc and source.type == 'tableindex' then
1329+
vm.compileByParentNode(source.node, vm.ANY, function (src)
1330+
if src.type == 'doc.field'
1331+
or src.type == 'doc.type.field' then
1332+
if vm.isSubType(guide.getUri(source), vm.compileNode(source.index), vm.compileNode(src.field or src.name)) then
1333+
hasMarkDoc = true
1334+
vm.setNode(source, vm.compileNode(src))
1335+
end
1336+
end
1337+
end)
1338+
end
1339+
13281340
if not hasMarkDoc and source.value then
13291341
vm.setNode(source, vm.compileNode(source.value))
13301342
end

test/diagnostics/type-check.lua

+11
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,17 @@ local B = "World"
11171117
local x = A
11181118
]]
11191119

1120+
TEST [[
1121+
local enum = { a = 1, b = 2 }
1122+
1123+
---@type { [integer] : boolean }
1124+
local t = {
1125+
<![enum.a]!> = 1,
1126+
<![enum.b]!> = 2,
1127+
<![3]!> = 3,
1128+
}
1129+
]]
1130+
11201131
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
11211132
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
11221133
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')

0 commit comments

Comments
 (0)