Skip to content

Commit

Permalink
don't use nil as value
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Apr 14, 2022
1 parent bfe3e71 commit bf334a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 11 additions & 9 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1466,3 +1466,8 @@ G = {}
<?G?>:A()
]]

TEST 'A' [[
---@type A
local <?x?> = nil
]]

0 comments on commit bf334a7

Please sign in to comment.