From ef7d4030ff86eedd0e667b3e7fe4b06ca4aec5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 16 Dec 2022 15:14:13 +0800 Subject: fix --- script/vm/tracer.lua | 29 +++++++++++++++-------------- test/type_inference/init.lua | 13 +++++++++++++ 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() end ]] + +TEST 'number' [[ +---@type number? +local x + +do + if not x then + return + end +end + +print() +]] -- cgit v1.2.3