Skip to content

Commit

Permalink
fix #1871
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Feb 2, 2023
1 parent e28d88a commit 36ed61d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* `FIX` [#1864]
* `FIX` [#1868]
* `FIX` [#1869]
* `FIX` [#1871]

[#1864]: https://github.com/sumneko/lua-language-server/issues/1864
[#1868]: https://github.com/sumneko/lua-language-server/issues/1868
[#1869]: https://github.com/sumneko/lua-language-server/issues/1869
[#1871]: https://github.com/sumneko/lua-language-server/issues/1871

## 3.6.8
`2023-1-31`
Expand Down
10 changes: 5 additions & 5 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ local searchFieldSwitch = util.switch()
or not math.tointeger(key) then
return
end
pushResult(source.node)
pushResult(source.node, true)
end
if type(key) == 'table' then
if vm.isSubType(suri, key, 'integer') then
pushResult(source.node)
pushResult(source.node, true)
end
end
end)
Expand All @@ -217,21 +217,21 @@ local searchFieldSwitch = util.switch()
or (fn.name == 'number' and type(key) == 'number')
or (fn.name == 'integer' and math.tointeger(key))
or (fn.name == 'string' and type(key) == 'string') then
pushResult(field)
pushResult(field, true)
end
elseif fn.type == 'doc.type.string'
or fn.type == 'doc.type.integer'
or fn.type == 'doc.type.boolean' then
if key == vm.ANY
or fn[1] == key then
pushResult(field)
pushResult(field, true)
end
end
end
end
if fieldKey.type == 'doc.field.name' then
if key == vm.ANY or fieldKey[1] == key then
pushResult(field)
pushResult(field, true)
end
end
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 @@ -1190,6 +1190,17 @@ end
print(is_string(3))
]]

TEST [[
---@class SomeClass
---@field [1] string
-- ...
---@param some_param SomeClass|SomeClass[]
local function some_fn(some_param) return end
some_fn { { "test" } } -- <- diagnostic: "Cannot assign `table` to `string`."
]]

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 36ed61d

Please sign in to comment.