Skip to content

Commit 41f0744

Browse files
committed
fix #1320
1 parent 2abeaaf commit 41f0744

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Diff for: changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* `FIX` [#1292](https://github.com/sumneko/lua-language-server/issues/1292)
2626
* `FIX` [#1294](https://github.com/sumneko/lua-language-server/issues/1294)
2727
* `FIX` [#1317](https://github.com/sumneko/lua-language-server/issues/1317)
28+
* `FIX` [#1320](https://github.com/sumneko/lua-language-server/issues/1320)
2829

2930
## 3.4.2
3031
`2022-7-6`

Diff for: script/vm/runner.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function mt:_lookIntoChild(action, topNode, outNode)
136136
if action.op.type == 'not' then
137137
outNode = outNode or topNode:copy()
138138
outNode, topNode = self:_lookIntoChild(action[1], topNode, outNode)
139+
outNode = outNode:copy()
139140
end
140141
elseif action.type == 'binary' then
141142
if not action[1] or not action[2] then
@@ -242,8 +243,13 @@ function mt:_lookIntoChild(action, topNode, outNode)
242243
mainNode = topNode:copy()
243244
end
244245
blockNode = self:_lookIntoBlock(action, blockNode:copy())
245-
if mainNode then
246-
topNode = mainNode:merge(blockNode)
246+
topNode = mainNode:merge(blockNode)
247+
if action.filter then
248+
-- look into filter again
249+
guide.eachSource(action.filter, function (src)
250+
self._mark[src] = nil
251+
end)
252+
blockNode, topNode = self:_lookIntoChild(action.filter, topNode:copy(), topNode:copy())
247253
end
248254
elseif action.type == 'if' then
249255
local hasElse

Diff for: script/vm/value.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function vm.testCondition(source)
2323
hasFalse = true
2424
end
2525
elseif n.type == 'global' and n.cate == 'type' then
26-
if n.name == 'boolean' then
26+
if n.name == 'boolean'
27+
or n.name == 'unknown' then
2728
return nil
2829
end
2930
if n.name == 'false'

Diff for: test/type_inference/init.lua

+23
Original file line numberDiff line numberDiff line change
@@ -3680,3 +3680,26 @@ local t
36803680
36813681
local <?x?> = t and t[i]
36823682
]]
3683+
3684+
TEST 'number' [[
3685+
---@type number
3686+
local x
3687+
3688+
if not <?x?>.y then
3689+
x = nil
3690+
end
3691+
]]
3692+
3693+
TEST 'number' [[
3694+
---@type number|nil
3695+
local x
3696+
while x == nil do
3697+
if x == nil then
3698+
return
3699+
end
3700+
3701+
x = nil
3702+
end
3703+
3704+
print(<?x?>)
3705+
]]

0 commit comments

Comments
 (0)