From abb5dbc6d8ff2371a2f81db0849ef71548f3cb6b Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 22 Jan 2026 19:10:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=90=8E?= =?UTF-8?q?=E7=BD=AE=E9=80=92=E5=A2=9E=E9=80=92=E5=87=8F=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=AC=A6=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 str_repeat($op, 2) 正确生成后置操作符代码 - 修复非变量表达式的错误处理逻辑 - 添加后置递增递减操作符的测试用例 --- src/Php/CompilerBase.php | 4 ++-- tests/aot/postincdec.phpt | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/aot/postincdec.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 54f6dcd2..9926e5f5 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1521,7 +1521,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parsePostOp($expr, string $op): string { if ($this->isVarExpr($expr->var)) { - return $this->parseIdentifier($expr->var) . '++'; + return $this->parseIdentifier($expr->var) . str_repeat($op, 2); } elseif ($this->isPropertyFetch($expr->var)) { $obj = $this->parseIdentifier($expr->var->var); $prop = $this->identifierToStr($expr->var->name); @@ -1539,7 +1539,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->afterStmtLines[] = 'php::setStaticProperty(' . $class . ', ' . $prop . ', ' . $tmpVar . ' ' . $op . ' 1);'; return $tmpVar; } - abort($expr, "Post-increment operator is not supported for non-variable expressions"); + $this->parsePostOp($expr, "Post-increment operator is not supported for non-variable expressions"); } protected function parsePostDec($expr): string diff --git a/tests/aot/postincdec.phpt b/tests/aot/postincdec.phpt new file mode 100644 index 00000000..a7f3a5af --- /dev/null +++ b/tests/aot/postincdec.phpt @@ -0,0 +1,15 @@ +--TEST-- +postinc/dec +--FILE-- + +--EXPECT-- +int(3) +int(4)