diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 14:39:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 14:39:42 +0800 |
commit | 8c56e6ba9d85f3e01fb3658901386ee89de847ab (patch) | |
tree | 1430ef6c8f84e7bd3db3e7f497d69c8de2f1df62 /script/core/diagnostics | |
parent | 5c0f9c4672b564da6d54ac8649afe199e4d7b1d7 (diff) | |
download | lua-language-server-8c56e6ba9d85f3e01fb3658901386ee89de847ab.zip |
update
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r-- | script/core/diagnostics/param-type-mismatch.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/script/core/diagnostics/param-type-mismatch.lua b/script/core/diagnostics/param-type-mismatch.lua index a05b03e4..e4917456 100644 --- a/script/core/diagnostics/param-type-mismatch.lua +++ b/script/core/diagnostics/param-type-mismatch.lua @@ -42,20 +42,31 @@ 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) local defNode = getDefNode(funcNode, i) - if defNode then - if not vm.canCastType(uri, defNode, refNode) then - callback { - start = arg.start, - finish = arg.finish, - message = lang.script('DIAG_PARAM_TYPE_MISMATCH', { - def = vm.getInfer(defNode):view(uri), - ref = vm.getInfer(refNode):view(uri), - }) - } - end + if not defNode then + goto CONTINUE + end + if arg.type == 'getfield' + or arg.type == 'getindex' then + -- 由于无法对字段进行类型收窄, + -- 因此将假值移除再进行检查 + refNode = refNode:copy():setTruthy() + end + if not vm.canCastType(uri, defNode, refNode) then + callback { + start = arg.start, + finish = arg.finish, + message = lang.script('DIAG_PARAM_TYPE_MISMATCH', { + def = vm.getInfer(defNode):view(uri), + ref = vm.getInfer(refNode):view(uri), + }) + } end + ::CONTINUE:: end end) end |