Skip to content

Commit 6e8e073

Browse files
committed
fix assert dose not remove type nil
1 parent 14bf8a0 commit 6e8e073

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

script/vm/node.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function mt:setTruthy()
131131
for index = #self, 1, -1 do
132132
local c = self[index]
133133
if c.type == 'nil'
134+
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
134135
or (c.type == 'boolean' and c[1] == false)
135136
or (c.type == 'doc.type.boolean' and c[1] == false) then
136137
table.remove(self, index)
@@ -163,6 +164,7 @@ function mt:setFalsy()
163164
for index = #self, 1, -1 do
164165
local c = self[index]
165166
if c.type == 'nil'
167+
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
166168
or (c.type == 'boolean' and c[1] == true)
167169
or (c.type == 'doc.type.boolean' and c[1] == true) then
168170
goto CONTINUE

test/type_inference/init.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,24 @@ assert(x ~= nil)
19791979
print(<?x?>)
19801980
]]
19811981

1982+
TEST 'integer' [[
1983+
---@type integer | nil
1984+
local x
1985+
1986+
assert(x)
1987+
1988+
print(<?x?>)
1989+
]]
1990+
1991+
TEST 'integer' [[
1992+
---@type integer | nil
1993+
local x
1994+
1995+
assert(x ~= nil)
1996+
1997+
print(<?x?>)
1998+
]]
1999+
19822000
TEST 'integer' [[
19832001
local x
19842002

0 commit comments

Comments
 (0)