summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-14 23:26:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-14 23:26:59 +0800
commitbf334a76c7ebff9da14292061a8f4a904ff38465 (patch)
treedcb7f409561a68f4047c5e37c5fc680774ce6807
parentbfe3e71009a4bb575a9978a4b5749b10122a2bc6 (diff)
downloadlua-language-server-bf334a76c7ebff9da14292061a8f4a904ff38465.zip
don't use `nil` as value
-rw-r--r--script/vm/compiler.lua20
-rw-r--r--test/type_inference/init.lua5
2 files changed, 16 insertions, 9 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 173cf7d7..05057e68 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -499,7 +499,9 @@ local function compileByLocalID(source)
for _, src in ipairs(sources) do
if src.value then
if not hasMarkDoc or guide.isLiteral(src.value) then
- vm.setNode(source, vm.compileNode(src.value))
+ if src.value.type ~= 'nil' then
+ vm.setNode(source, vm.compileNode(src.value))
+ end
end
end
end
@@ -727,7 +729,7 @@ local function compileLocalBase(source)
hasMarkValue = true
if source.value.type == 'table' then
vm.setNode(source, source.value)
- else
+ elseif source.value.type ~= 'nil' then
vm.setNode(source, vm.compileNode(source.value))
end
end
@@ -940,12 +942,10 @@ local compilerSwitch = util.switch()
if source.value then
if not hasMarkDoc or guide.isLiteral(source.value) then
- if source.value then
- if source.value.type == 'table' then
- vm.setNode(source, source.value)
- else
- vm.setNode(source, vm.compileNode(source.value))
- end
+ if source.value.type == 'table' then
+ vm.setNode(source, source.value)
+ elseif source.value.type ~= 'nil' then
+ vm.setNode(source, vm.compileNode(source.value))
end
end
end
@@ -1598,7 +1598,9 @@ local function compileByGlobal(source)
for _, set in ipairs(global:getSets(uri)) do
if set.value then
if not hasMarkDoc or guide.isLiteral(set.value) then
- globalNode:merge(vm.compileNode(set.value))
+ if set.value.type ~= 'nil' then
+ globalNode:merge(vm.compileNode(set.value))
+ end
end
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 4787dd56..7b5fb332 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1466,3 +1466,8 @@ G = {}
<?G?>:A()
]]
+
+TEST 'A' [[
+---@type A
+local <?x?> = nil
+]]