diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-11 17:45:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-11 17:45:39 +0800 |
commit | 41f0744c4e601ec80e63cce15b6e50f02f6e4a71 (patch) | |
tree | 7f42eaa2e162578db943eef9fce74580c08f766d | |
parent | 2abeaaf81dd8c288a27a2c9638bf5b527ece3463 (diff) | |
download | lua-language-server-41f0744c4e601ec80e63cce15b6e50f02f6e4a71.zip |
fix #1320
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/runner.lua | 10 | ||||
-rw-r--r-- | script/vm/value.lua | 3 | ||||
-rw-r--r-- | test/type_inference/init.lua | 23 |
4 files changed, 34 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md index f99502bb..ca84a9b3 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,7 @@ * `FIX` [#1292](https://github.com/sumneko/lua-language-server/issues/1292) * `FIX` [#1294](https://github.com/sumneko/lua-language-server/issues/1294) * `FIX` [#1317](https://github.com/sumneko/lua-language-server/issues/1317) +* `FIX` [#1320](https://github.com/sumneko/lua-language-server/issues/1320) ## 3.4.2 `2022-7-6` diff --git a/script/vm/runner.lua b/script/vm/runner.lua index dcfe83b2..36bab8bf 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -136,6 +136,7 @@ function mt:_lookIntoChild(action, topNode, outNode) if action.op.type == 'not' then outNode = outNode or topNode:copy() outNode, topNode = self:_lookIntoChild(action[1], topNode, outNode) + outNode = outNode:copy() end elseif action.type == 'binary' then if not action[1] or not action[2] then @@ -242,8 +243,13 @@ function mt:_lookIntoChild(action, topNode, outNode) mainNode = topNode:copy() end blockNode = self:_lookIntoBlock(action, blockNode:copy()) - if mainNode then - topNode = mainNode:merge(blockNode) + topNode = mainNode:merge(blockNode) + if action.filter then + -- look into filter again + guide.eachSource(action.filter, function (src) + self._mark[src] = nil + end) + blockNode, topNode = self:_lookIntoChild(action.filter, topNode:copy(), topNode:copy()) end elseif action.type == 'if' then local hasElse diff --git a/script/vm/value.lua b/script/vm/value.lua index bbae446c..7eab4a8e 100644 --- a/script/vm/value.lua +++ b/script/vm/value.lua @@ -23,7 +23,8 @@ function vm.testCondition(source) hasFalse = true end elseif n.type == 'global' and n.cate == 'type' then - if n.name == 'boolean' then + if n.name == 'boolean' + or n.name == 'unknown' then return nil end if n.name == 'false' diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 3a24e5d0..de66517d 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3680,3 +3680,26 @@ local t local <?x?> = t and t[i] ]] + +TEST 'number' [[ +---@type number +local x + +if not <?x?>.y then + x = nil +end +]] + +TEST 'number' [[ +---@type number|nil +local x +while x == nil do + if x == nil then + return + end + + x = nil +end + +print(<?x?>) +]] |