summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/node.lua2
-rw-r--r--test/type_inference/init.lua18
2 files changed, 20 insertions, 0 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 8b2bafd7..6023b1c3 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -131,6 +131,7 @@ function mt:setTruthy()
for index = #self, 1, -1 do
local c = self[index]
if c.type == 'nil'
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
or (c.type == 'boolean' and c[1] == false)
or (c.type == 'doc.type.boolean' and c[1] == false) then
table.remove(self, index)
@@ -163,6 +164,7 @@ function mt:setFalsy()
for index = #self, 1, -1 do
local c = self[index]
if c.type == 'nil'
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
or (c.type == 'boolean' and c[1] == true)
or (c.type == 'doc.type.boolean' and c[1] == true) then
goto CONTINUE
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index fb34da17..617d34db 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1980,6 +1980,24 @@ print(<?x?>)
]]
TEST 'integer' [[
+---@type integer | nil
+local x
+
+assert(x)
+
+print(<?x?>)
+]]
+
+TEST 'integer' [[
+---@type integer | nil
+local x
+
+assert(x ~= nil)
+
+print(<?x?>)
+]]
+
+TEST 'integer' [[
local x
assert(x == 1)