summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-16 15:14:13 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-16 15:14:13 +0800
commitef7d4030ff86eedd0e667b3e7fe4b06ca4aec5fe (patch)
treeebd88956154a1df96073e2ee98e56968c345be82
parent7155b72aea44f631141ab84748e6052cb9da0838 (diff)
downloadlua-language-server-ef7d4030ff86eedd0e667b3e7fe4b06ca4aec5fe.zip
fix
-rw-r--r--script/vm/tracer.lua29
-rw-r--r--test/type_inference/init.lua13
2 files changed, 28 insertions, 14 deletions
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua
index f8d99800..b97df135 100644
--- a/script/vm/tracer.lua
+++ b/script/vm/tracer.lua
@@ -326,10 +326,10 @@ function mt:lookIntoChild(action, topNode, outNode)
self:lookIntoBlock(action, actionStart, topNode:copy())
local lastAssign = self:getLastAssign(action.start, action.finish)
if lastAssign then
- local node = self:getNode(lastAssign)
- if node then
- topNode = node:copy()
- end
+ self:getNode(lastAssign)
+ end
+ if self.nodes[action] then
+ topNode = self.nodes[action]:copy()
end
end
elseif action.type == 'while' then
@@ -344,10 +344,10 @@ function mt:lookIntoChild(action, topNode, outNode)
self:lookIntoBlock(action, action.keyword[4], blockNode:copy())
local lastAssign = self:getLastAssign(action.start, action.finish)
if lastAssign then
- local node = self:getNode(lastAssign)
- if node then
- topNode = mainNode:merge(node)
- end
+ self:getNode(lastAssign)
+ end
+ if self.nodes[action] then
+ topNode = mainNode:merge(self.nodes[action])
end
end
if action.filter then
@@ -388,11 +388,11 @@ function mt:lookIntoChild(action, topNode, outNode)
else
local lastAssign = self:getLastAssign(subBlock.start, subBlock.finish)
if lastAssign then
- local node = self:getNode(lastAssign)
- if node then
- blockNodes[#blockNodes+1] = node
- mergedNode = true
- end
+ self:getNode(lastAssign)
+ end
+ if self.nodes[subBlock] then
+ blockNodes[#blockNodes+1] = self.nodes[subBlock]
+ mergedNode = true
end
end
end
@@ -461,10 +461,11 @@ function mt:lookIntoBlock(block, start, node)
node = self:lookIntoChild(action, node)
end
if action.finish > start and self.assignMap[action] then
- break
+ return
end
::CONTINUE::
end
+ self.nodes[block] = node
end
---@param source parser.object
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 85cbf683..e89133c2 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -4080,3 +4080,16 @@ local function x()
print(<?x?>)
end
]]
+
+TEST 'number' [[
+---@type number?
+local x
+
+do
+ if not x then
+ return
+ end
+end
+
+print(<?x?>)
+]]