summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-14 18:25:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-14 18:25:41 +0800
commiteb7363f1c70e62d0f27c675f49b0d28113d4afa4 (patch)
tree6de7a143ddaa18685a567ec7046db2afa18cf817
parent2b0fcec7b17c2c01942a277e938f918dc52ff62c (diff)
downloadlua-language-server-eb7363f1c70e62d0f27c675f49b0d28113d4afa4.zip
update
-rw-r--r--script/vm/runner.lua27
-rw-r--r--test/type_inference/init.lua25
2 files changed, 42 insertions, 10 deletions
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index 2e301ed3..c0218a44 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -127,21 +127,27 @@ function mt:_lookInto(action, topNode, outNode)
self:_launchBlock(action, blockNode:copy())
topNode = mainNode
elseif action.type == 'if' then
- local mainNode = topNode:copy()
- local blockNode = topNode:copy()
+ local mainNode = topNode:copy()
+ local blockNodes = {}
for _, subBlock in ipairs(action) do
- if subBlock.type == 'ifblock' then
+ local blockNode = mainNode:copy()
+ if subBlock.filter then
blockNode, mainNode = self:_lookInto(subBlock.filter, blockNode, mainNode)
self:_fastWard(subBlock.filter.finish, blockNode)
- blockNode = self:_launchBlock(subBlock, blockNode:copy())
- local neverReturn = subBlock.hasReturn
- or subBlock.hasGoTo
- or subBlock.hasBreak
- if not neverReturn then
- mainNode:merge(blockNode)
- end
+ else
+ mainNode:clear()
+ end
+ blockNode = self:_launchBlock(subBlock, blockNode:copy())
+ local neverReturn = subBlock.hasReturn
+ or subBlock.hasGoTo
+ or subBlock.hasBreak
+ if not neverReturn then
+ blockNodes[#blockNodes+1] = blockNode
end
end
+ for _, blockNode in ipairs(blockNodes) do
+ mainNode:merge(blockNode)
+ end
topNode = mainNode
elseif action.type == 'getlocal' then
if action.node == self._loc then
@@ -184,6 +190,7 @@ function mt:_lookInto(action, topNode, outNode)
end
end
if loc then
+ self:_fastWard(loc.finish, topNode)
if guide.isLiteral(checker) then
local checkerNode = vm.compileNode(checker)
if action.op.type == '==' then
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 7d0fec91..2dd6971b 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -2257,6 +2257,19 @@ local x
print(<?x?>)
]]
+TEST 'unknown?' [[
+---@type string?
+local x
+
+if x then
+ return
+else
+ print(<?x?>)
+end
+
+print(x)
+]]
+
TEST 'string' [[
---@type string?
local x
@@ -2318,6 +2331,18 @@ end
print(<?t?>)
]]
+TEST 'unknown?' [[
+---@type integer?
+local t
+
+if t then
+else
+ print(<?t?>)
+end
+
+print(t)
+]]
+
TEST 'table|unknown' [[
local function f()
if x then