diff --git a/src/Php/AstNodeType.php b/src/Php/AstNodeType.php index e7d27598..e4917fa5 100644 --- a/src/Php/AstNodeType.php +++ b/src/Php/AstNodeType.php @@ -111,4 +111,22 @@ trait AstNodeType { return $expr instanceof VariadicPlaceholder; } + + protected function isReturnExpr(NodeAbstract $expr): bool + { + return $expr instanceof Node\Stmt\Return_; + } + + protected function isBreakExpr(NodeAbstract $expr): bool + { + return $expr instanceof Node\Stmt\Break_; + } + + protected function isExitExpr(NodeAbstract $expr): bool + { + if ($expr instanceof Node\Stmt) { + $expr = $expr->expr; + } + return $expr instanceof Node\Expr\Exit_; + } } diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 83cceb91..a9641ff4 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3214,8 +3214,8 @@ class CompilerBase extends \PhpAot\Core\Translator $stmts = $stmts[0]->stmts; } $lastExpr = end($stmts); - if (!($lastExpr instanceof Node\Stmt\Return_ or $lastExpr instanceof Node\Stmt\Break_)) { - $this->fatalError($case, 'switch case must end with return or break, given ' . $lastExpr->getType()); + if (!$this->isReturnExpr($lastExpr) and !$this->isExitExpr($lastExpr) and !$this->isBreakExpr($lastExpr)) { + $this->fatalError($case, 'switch case must end with return or break or exit, ' . $lastExpr->getType() . ' given'); } if ($condList) {