diff options
-rw-r--r-- | script/parser/guide.lua | 3 | ||||
-rw-r--r-- | script/parser/newparser.lua | 14 | ||||
-rw-r--r-- | script/vm/runner.lua | 3 | ||||
-rw-r--r-- | test/type_inference/init.lua | 11 |
4 files changed, 26 insertions, 5 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index b008c69b..a934892e 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -57,6 +57,8 @@ local type = type ---@field step parser.object ---@field redundant { max: integer, passed: integer } ---@field filter parser.object +---@field hasGoTo? true +---@field hasReturn? true ---@field _root parser.object ---@class guide @@ -416,6 +418,7 @@ function m.getUri(obj) return '' end +---@return parser.object function m.getENV(source, start) if not start then start = 1 diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 4bddd7e5..35854c9b 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -2963,10 +2963,7 @@ local function parseReturn() if block.type == 'ifblock' or block.type == 'elseifblock' or block.type == 'else' then - if not block.returns then - block.returns = {} - end - block.returns[#block.returns+1] = rtn + block.hasReturn = true break end end @@ -3066,6 +3063,15 @@ local function parseGoTo() break end end + for i = #Chunk, 1, -1 do + local chunk = Chunk[i] + if chunk.type == 'ifblock' + or chunk.type == 'elseifblock' + or chunk.type == 'elseblock' then + chunk.hasGoTo = true + break + end + end pushActionIntoCurrentChunk(action) return action diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 2be187c9..75de2c0f 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -192,7 +192,8 @@ function mt:_compileBlock(block) } self.steps[#self.steps+1] = blockStep self:_compileNarrowByFilter(childBlock.filter, outStep, blockStep) - if not childBlock.returns then + if not childBlock.hasReturn + and not childBlock.hasGoTo then finals[#finals+1] = blockStep end self.steps[#self.steps+1] = { diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index df1f538b..fa677fa9 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -1855,6 +1855,17 @@ end print(<?x?>) ]] +TEST 'integer' [[ +---@type integer? +local x + +if not x then + goto ANYWHERE +end + +print(<?x?>) +]] + TEST 'integer' [=[ local x |