From 8faac7d9726871237905a14347329d694a7c0494 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 1 Jun 2026 15:15:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=B0=83=E7=94=A8=E8=A7=A3=E6=9E=90=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正了 BackendOptionsTest 中的优化级别断言,从 /O2 改为 /O1 - 修复了 CompilerBase 中的方法名参数传递错误,将 $method 改为 $methodName - 在无法调用方法时添加了致命错误提示 - 删除了 PreprocessorTest 中已弃用的缓存测试方法 --- phpunit/src/Backend/BackendOptionsTest.php | 2 +- phpunit/src/PreprocessorTest.php | 15 --------------- src/Php/CompilerBase.php | 3 ++- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/phpunit/src/Backend/BackendOptionsTest.php b/phpunit/src/Backend/BackendOptionsTest.php index f16e722c..e30fff17 100644 --- a/phpunit/src/Backend/BackendOptionsTest.php +++ b/phpunit/src/Backend/BackendOptionsTest.php @@ -441,7 +441,7 @@ class BackendOptionsTest extends TestCase // O1 $opt1 = $compiler->buildCompileOptions(['optimize' => 1]); - $this->assertStringContainsString('/O2', $opt1); + $this->assertStringContainsString('/O1', $opt1); // O2 $opt2 = $compiler->buildCompileOptions(['optimize' => 2]); diff --git a/phpunit/src/PreprocessorTest.php b/phpunit/src/PreprocessorTest.php index e5cb1048..ff3ddb0d 100644 --- a/phpunit/src/PreprocessorTest.php +++ b/phpunit/src/PreprocessorTest.php @@ -187,21 +187,6 @@ class PreprocessorTest extends TestCase $this->assertEquals('App\\Entity\\Base', $result); } - // ======================================================================== - // hasCppFileCache - // ======================================================================== - - public function testHasCppFileCacheWhenDisabled(): void - { - // enableCache defaults to false, so cache should always return false - $this->assertFalse($this->compiler->hasCppFileCache('/tmp/test.php')); - } - - public function testHasCppFileCacheNonexistentFile(): void - { - $this->assertFalse($this->compiler->hasCppFileCache('/nonexistent/path/test.php')); - } - // ======================================================================== // sortFiles // ======================================================================== diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 2614913b..fcc31613 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -5412,8 +5412,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($type === self::TYPE_STREAM) { return $this->genStreamNullGuard($expr, $object, $methodName, $fn); } - return $this->parseUniversalMethodCall($expr, $object, $method, $fn); + return $this->parseUniversalMethodCall($expr, $object, $methodName, $fn); } + $this->fatalError($expr, "Cannot call method `{$methodName}()` on variable of type {$type}"); } $this->context->beforeStmtLines[] = '// Method Call: ' . $object . '->' . $this->parseIdentifier($expr->name) . '()'; try {