diff --git a/lib/core/Handles/HandlesAsyncFunctions.py b/lib/core/Handles/HandlesAsyncFunctions.py index 2bb8415..7b32ba4 100644 --- a/lib/core/Handles/HandlesAsyncFunctions.py +++ b/lib/core/Handles/HandlesAsyncFunctions.py @@ -531,12 +531,19 @@ class AsyncFunctionHandle(BaseHandle): self._HandleCoroFor(stmt, Gen) continue if isinstance(stmt, ast.Break): - if Gen.loop_break_targets: - Gen.builder.branch(Gen.loop_break_targets[-1]) + if not Gen.loop_break_targets: + # fail-fast:协程体内、循环之外的 break 无处可跳(不兜底) + from lib.core.LLVMCG.FuncGen import FailFastError + raise FailFastError( + "break 只能用在循环或 match-case 体内(当前没有可跳出的目标)") + Gen.builder.branch(Gen.loop_break_targets[-1]) continue if isinstance(stmt, ast.Continue): - if Gen.loop_continue_targets: - Gen.builder.branch(Gen.loop_continue_targets[-1]) + if not Gen.loop_continue_targets: + from lib.core.LLVMCG.FuncGen import FailFastError + raise FailFastError( + "continue 只能用在循环体内(当前没有可继续的循环)") + Gen.builder.branch(Gen.loop_continue_targets[-1]) continue if isinstance(stmt, ast.Pass): continue diff --git a/lib/core/Handles/HandlesFor.py b/lib/core/Handles/HandlesFor.py index 1dff047..b9d698c 100644 --- a/lib/core/Handles/HandlesFor.py +++ b/lib/core/Handles/HandlesFor.py @@ -417,6 +417,8 @@ class ForHandle(BaseHandle): self.Trans.FunctionHandler._EmitFunctionLlvm(Node, Gen, extra_params=extra_params if extra_params else None) Gen.builder = saved_builder Gen.func = saved_func + Gen.loop_break_targets = saved_loop_break_targets + Gen.loop_continue_targets = saved_loop_continue_targets Gen.variables = saved_variables Gen._reg_values = saved_reg_values Gen.global_vars = saved_global_vars