summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-20 22:41:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-20 22:41:29 +0800
commit28d5a33077b28dcbb52974aaf90125cee013342b (patch)
tree59fd46d990a0f0ca5c5c05808dde882280717540 /script/vm
parent58df10c5d5957b8437e76e271f7c7c1a41aca105 (diff)
downloadlua-language-server-28d5a33077b28dcbb52974aaf90125cee013342b.zip
update `array[1] = nil`
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/type.lua28
1 files changed, 14 insertions, 14 deletions
diff --git a/script/vm/type.lua b/script/vm/type.lua
index c2871233..74e98ec2 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -223,21 +223,21 @@ function vm.canCastType(uri, defNode, refNode)
return true
end
- -- allow `local x = {};x = nil`,
- -- but not allow `local x ---@type table;x = nil`
- local allowNil = defInfer:hasType(uri, 'table')
- and not defNode:hasType 'table'
-
- -- allow `local x = 0;x = 1.0`,
- -- but not allow `local x ---@type integer;x = 1.0`
- local allowNumber = defInfer:hasType(uri, 'integer')
- and not defNode:hasType 'integer'
-
- if allowNil and vm.isSubType(uri, refNode, 'nil') then
- return true
+ if vm.isSubType(uri, refNode, 'nil') then
+ -- allow `local x = {};x = nil`,
+ -- but not allow `local x ---@type table;x = nil`
+ if defInfer:hasType(uri, 'table')
+ and not defNode:hasType 'table' then
+ return true
+ end
end
- if allowNumber and vm.isSubType(uri, refNode, 'number') then
- return true
+ if vm.isSubType(uri, refNode, 'number') then
+ -- allow `local x = 0;x = 1.0`,
+ -- but not allow `local x ---@type integer;x = 1.0`
+ if defInfer:hasType(uri, 'integer')
+ and not defNode:hasType 'integer' then
+ return true
+ end
end
if vm.isSubType(uri, refNode, defNode) then
return true