From 58b6d4fad4b9e317f86668917c6f573b30bdadc1 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 9 Apr 2026 17:29:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=A3=B0=E6=98=8E=E4=B8=AD=E7=9A=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在函数编译过程中添加了对返回类型的正确处理分支 - 确保当函数具有返回类型声明时不跳过必要的代码生成步骤 - 添加了测试用例验证可迭代类型声明的功能 - 修复了可能导致编译错误的条件判断逻辑 --- src/Php/CompilerBase.php | 2 ++ tests/aot/type_decl/005.phpt | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/aot/type_decl/005.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ebcb034f..f447b905 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -837,6 +837,8 @@ class CompilerBase extends \PhpAot\Core\Translator $this->climate->cyan('Skip function ' . $name); } $this->indentLevel--; + } else { + $stmts = $this->genReturnCode(); } $functionDeclCode = $this->getReturnType() . ' ' . self::PREFIX . $name . '('; diff --git a/tests/aot/type_decl/005.phpt b/tests/aot/type_decl/005.phpt new file mode 100644 index 00000000..a602c80b --- /dev/null +++ b/tests/aot/type_decl/005.phpt @@ -0,0 +1,14 @@ +--TEST-- +Type Declarations +--FILE-- + +--EXPECT-- +string(4) "main"