Skip to content

Commit bf334a7

Browse files
committed
don't use nil as value
1 parent bfe3e71 commit bf334a7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

script/vm/compiler.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ local function compileByLocalID(source)
499499
for _, src in ipairs(sources) do
500500
if src.value then
501501
if not hasMarkDoc or guide.isLiteral(src.value) then
502-
vm.setNode(source, vm.compileNode(src.value))
502+
if src.value.type ~= 'nil' then
503+
vm.setNode(source, vm.compileNode(src.value))
504+
end
503505
end
504506
end
505507
end
@@ -727,7 +729,7 @@ local function compileLocalBase(source)
727729
hasMarkValue = true
728730
if source.value.type == 'table' then
729731
vm.setNode(source, source.value)
730-
else
732+
elseif source.value.type ~= 'nil' then
731733
vm.setNode(source, vm.compileNode(source.value))
732734
end
733735
end
@@ -940,12 +942,10 @@ local compilerSwitch = util.switch()
940942

941943
if source.value then
942944
if not hasMarkDoc or guide.isLiteral(source.value) then
943-
if source.value then
944-
if source.value.type == 'table' then
945-
vm.setNode(source, source.value)
946-
else
947-
vm.setNode(source, vm.compileNode(source.value))
948-
end
945+
if source.value.type == 'table' then
946+
vm.setNode(source, source.value)
947+
elseif source.value.type ~= 'nil' then
948+
vm.setNode(source, vm.compileNode(source.value))
949949
end
950950
end
951951
end
@@ -1598,7 +1598,9 @@ local function compileByGlobal(source)
15981598
for _, set in ipairs(global:getSets(uri)) do
15991599
if set.value then
16001600
if not hasMarkDoc or guide.isLiteral(set.value) then
1601-
globalNode:merge(vm.compileNode(set.value))
1601+
if set.value.type ~= 'nil' then
1602+
globalNode:merge(vm.compileNode(set.value))
1603+
end
16021604
end
16031605
end
16041606
end

test/type_inference/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,3 +1466,8 @@ G = {}
14661466
14671467
<?G?>:A()
14681468
]]
1469+
1470+
TEST 'A' [[
1471+
---@type A
1472+
local <?x?> = nil
1473+
]]

0 commit comments

Comments
 (0)