Skip to content

Commit

Permalink
should check type of self
Browse files Browse the repository at this point in the history
fix #1922
  • Loading branch information
sumneko committed Mar 8, 2023
1 parent dcfc5d2 commit c6820ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 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` [#1715]
* `FIX` [#1753]
* `FIX` [#1914]
* `FIX` [#1922]

[#1715]: https://github.com/LuaLS/lua-language-server/issues/1715
[#1753]: https://github.com/LuaLS/lua-language-server/issues/1753
[#1914]: https://github.com/LuaLS/lua-language-server/issues/1914
[#1922]: https://github.com/LuaLS/lua-language-server/issues/1922

## 3.6.13
`2023-3-2`
Expand Down
6 changes: 2 additions & 4 deletions script/core/diagnostics/param-type-mismatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ return function (uri, callback)
await.delay()
local funcNode = vm.compileNode(source.node)
for i, arg in ipairs(source.args) do
if i == 1 and source.node.type == 'getmethod' then
goto CONTINUE
end
local refNode = vm.compileNode(arg)
if not refNode then
goto CONTINUE
Expand All @@ -99,7 +96,8 @@ return function (uri, callback)
goto CONTINUE
end
if arg.type == 'getfield'
or arg.type == 'getindex' then
or arg.type == 'getindex'
or arg.type == 'self' then
-- 由于无法对字段进行类型收窄,
-- 因此将假值移除再进行检查
refNode = refNode:copy():setTruthy()
Expand Down
13 changes: 13 additions & 0 deletions test/diagnostics/type-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,19 @@ end
get_val('hi')
]]

TESTWITH 'param-type-mismatch' [[
---@class Class
local Class = {}
---@param source string
function Class.staticCreator(source)
end
Class.staticCreator(<!true!>)
Class<!:!>staticCreator() -- Expecting a waring
]]

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 c6820ed

Please sign in to comment.