diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-18 01:20:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-18 01:20:54 +0800 |
commit | 5099d8be7125b948691d099b0e0084a72620293b (patch) | |
tree | 2bc0b2cd2fc670b7babd2967225c17aed378e147 /script/core | |
parent | 6df9d8376bc5339a8c4218cc261dc76d7ac8e7ad (diff) | |
download | lua-language-server-5099d8be7125b948691d099b0e0084a72620293b.zip |
update
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/cast-local-type.lua | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/script/core/diagnostics/cast-local-type.lua b/script/core/diagnostics/cast-local-type.lua index 4b7f7e84..65cc0368 100644 --- a/script/core/diagnostics/cast-local-type.lua +++ b/script/core/diagnostics/cast-local-type.lua @@ -24,13 +24,25 @@ return function (uri, callback) if vm.getInfer(loc):hasUnknown(uri) then return end - local canSetNil = vm.getInfer(loc):hasClass(uri) - or vm.getInfer(loc):hasType(uri, 'table') + + -- allow `local x = {};x = nil`, + -- but not allow `local x ---@type table;x = nil` + local allowNil = vm.getInfer(loc):hasType(uri, 'table') + and not locNode:hasType 'table' + + -- allow `local x = 0;x = 1.0`, + -- but not allow `local x ---@type integer;x = 1.0` + local allowNumber = vm.getInfer(loc):hasType(uri, 'integer') + and not locNode:hasType 'integer' + for _, ref in ipairs(loc.ref) do if ref.type == 'setlocal' then await.delay() local refNode = vm.compileNode(ref) - if canSetNil and vm.getInfer(ref):view(uri) == 'nil' then + if allowNil and vm.isSubType(uri, refNode, 'nil') then + goto CONTINUE + end + if allowNumber and vm.isSubType(uri, refNode, 'number') then goto CONTINUE end if vm.isSubType(uri, refNode, locNode) then |