From 96b4e0ba089c717aa5455a7f6fcf6caee863a74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Jun 2022 15:36:03 +0800 Subject: resolve #1094 infer type by `error` --- script/parser/guide.lua | 1 + script/parser/newparser.lua | 11 +++++++++++ script/vm/runner.lua | 1 + 3 files changed, 13 insertions(+) (limited to 'script') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 83321bac..2894f673 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -65,6 +65,7 @@ local type = type ---@field hasGoTo? true ---@field hasReturn? true ---@field hasBreak? true +---@field hasError? true ---@field _root parser.object ---@class guide diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index fa728c8b..c7e9256a 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -2818,6 +2818,17 @@ local function compileExpAsAction(exp) end if exp.type == 'call' then + if exp.node.special == 'error' then + for i = #Chunk, 1, -1 do + local block = Chunk[i] + if block.type == 'ifblock' + or block.type == 'elseifblock' + or block.type == 'else' then + block.hasError = true + break + end + end + end return exp end diff --git a/script/vm/runner.lua b/script/vm/runner.lua index e7851b49..5d561677 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -153,6 +153,7 @@ function mt:_lookInto(action, topNode, outNode) local neverReturn = subBlock.hasReturn or subBlock.hasGoTo or subBlock.hasBreak + or subBlock.hasError if not neverReturn then blockNodes[#blockNodes+1] = blockNode end -- cgit v1.2.3