Skip to content

Commit

Permalink
infer types of tableindex by semantic
Browse files Browse the repository at this point in the history
fix #1831
  • Loading branch information
sumneko committed Jan 30, 2023
1 parent 02f6831 commit c69e65f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 3.6.8
* `FIX` [#1831]
[#1831]: https://github.com/sumneko/lua-language-server/issues/1831

## 3.6.7
`2023-1-20`
* `FIX` [#1810]
Expand Down
12 changes: 12 additions & 0 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,18 @@ local compilerSwitch = util.switch()
end
end

if not hasMarkDoc and source.type == 'tableindex' then
vm.compileByParentNode(source.node, vm.ANY, function (src)
if src.type == 'doc.field'
or src.type == 'doc.type.field' then
if vm.isSubType(guide.getUri(source), vm.compileNode(source.index), vm.compileNode(src.field or src.name)) then
hasMarkDoc = true
vm.setNode(source, vm.compileNode(src))
end
end
end)
end

if not hasMarkDoc and source.value then
vm.setNode(source, vm.compileNode(source.value))
end
Expand Down
11 changes: 11 additions & 0 deletions test/diagnostics/type-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,17 @@ local B = "World"
local x = A
]]

TEST [[
local enum = { a = 1, b = 2 }
---@type { [integer] : boolean }
local t = {
<![enum.a]!> = 1,
<![enum.b]!> = 2,
<![3]!> = 3,
}
]]

config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')
Expand Down

0 comments on commit c69e65f

Please sign in to comment.