diff options
-rw-r--r-- | script/vm/node.lua | 6 | ||||
-rw-r--r-- | script/vm/runner.lua | 11 | ||||
-rw-r--r-- | test/type_inference/init.lua | 16 |
3 files changed, 26 insertions, 7 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 2128edb2..16b5a8d8 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -20,13 +20,14 @@ mt.optional = nil mt.data = nil ---@param node vm.node | vm.node.object +---@return vm.node function mt:merge(node) if not node then - return + return self end if node.type == 'vm.node' then if node == self then - return + return self end if node:isOptional() then self.optional = true @@ -44,6 +45,7 @@ function mt:merge(node) self[#self+1] = node end end + return self end ---@return boolean diff --git a/script/vm/runner.lua b/script/vm/runner.lua index acf5427d..0dd33595 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -137,19 +137,20 @@ function mt:_lookInto(action, topNode, outNode) set = action action = value end - if action.type == 'function' - or action.type == 'loop' + if action.type == 'function' then + self:_launchBlock(action, topNode:copy()) + elseif action.type == 'loop' or action.type == 'in' or action.type == 'repeat' or action.type == 'for' then - self:_launchBlock(action, topNode:copy()) + topNode = self:_launchBlock(action, topNode:copy()) elseif action.type == 'while' then local blockNode, mainNode = self:_lookInto(action.filter, topNode:copy(), topNode:copy()) if action.filter then self:_fastWard(action.filter.finish, blockNode) end - self:_launchBlock(action, blockNode:copy()) - topNode = mainNode + blockNode = self:_launchBlock(action, blockNode:copy()) + topNode = mainNode:merge(blockNode) elseif action.type == 'if' then local hasElse local mainNode = topNode:copy() diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index db5a38fd..7b4185d7 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3126,3 +3126,19 @@ local f local _, <?n?> = f() ]] + +TEST 'string' [[ +local s +while true do + s = '' +end +print(<?s?>) +]] + +TEST 'string' [[ +local s +for _ in _ do + s = '' +end +print(<?s?>) +]] |