Skip to content

Commit c6820ed

Browse files
committed
should check type of self
fix #1922
1 parent dcfc5d2 commit c6820ed

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
* `FIX` [#1715]
55
* `FIX` [#1753]
66
* `FIX` [#1914]
7+
* `FIX` [#1922]
78

89
[#1715]: https://github.com/LuaLS/lua-language-server/issues/1715
910
[#1753]: https://github.com/LuaLS/lua-language-server/issues/1753
1011
[#1914]: https://github.com/LuaLS/lua-language-server/issues/1914
12+
[#1922]: https://github.com/LuaLS/lua-language-server/issues/1922
1113

1214
## 3.6.13
1315
`2023-3-2`

script/core/diagnostics/param-type-mismatch.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ return function (uri, callback)
8787
await.delay()
8888
local funcNode = vm.compileNode(source.node)
8989
for i, arg in ipairs(source.args) do
90-
if i == 1 and source.node.type == 'getmethod' then
91-
goto CONTINUE
92-
end
9390
local refNode = vm.compileNode(arg)
9491
if not refNode then
9592
goto CONTINUE
@@ -99,7 +96,8 @@ return function (uri, callback)
9996
goto CONTINUE
10097
end
10198
if arg.type == 'getfield'
102-
or arg.type == 'getindex' then
99+
or arg.type == 'getindex'
100+
or arg.type == 'self' then
103101
-- 由于无法对字段进行类型收窄,
104102
-- 因此将假值移除再进行检查
105103
refNode = refNode:copy():setTruthy()

test/diagnostics/type-check.lua

+13
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,19 @@ end
12111211
get_val('hi')
12121212
]]
12131213

1214+
TESTWITH 'param-type-mismatch' [[
1215+
---@class Class
1216+
local Class = {}
1217+
1218+
---@param source string
1219+
function Class.staticCreator(source)
1220+
1221+
end
1222+
1223+
Class.staticCreator(<!true!>)
1224+
Class<!:!>staticCreator() -- Expecting a waring
1225+
]]
1226+
12141227
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
12151228
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
12161229
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')

0 commit comments

Comments
 (0)