如果else分支只有注释,那就不渲染这个分支

pull/11/head
NathanFreeman 2 months ago
parent 8df3e8bfef
commit c73dedc306
  1. 2
      src/Php/CompilerBase.php
  2. 19
      tests/core/basic/empty-else.phpt

@ -4203,7 +4203,7 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont
protected function parseIfChain(array $arms, ?Node\Stmt\Else_ $else, int $index): string
{
if (!isset($arms[$index])) {
if (!$else) {
if (!$else || (count($else->stmts) == 1 && $else->stmts[0] instanceof Node\Stmt\Nop)) {
return '';
}
return $this->parseBlockStmts($else->stmts);

@ -0,0 +1,19 @@
--TEST--
empty else
--FILE--
<?php
function main() {
if (true) {
echo 'success';
} else {
// 1
# 1
/**
* 1
* 2
*/
}
}
?>
--EXPECT--
success
Loading…
Cancel
Save