From ee240aed2501eee0a2dac02c308559482ecf52b1 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 12 May 2026 12:50:59 +0800 Subject: [PATCH] =?UTF-8?q?test(php):=20=E6=B7=BB=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=AE=B9=E5=99=A8=E9=9D=99=E6=80=81=E7=B1=BB=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 testStdContainerStaticClassMismatch 测试方法验证对象分配错误 - 更新 StdContainerParser 中的 fatal error 消息格式保持一致性 --- phpunit/src/AssignTest.php | 8 ++++++++ src/Php/Parser/StdContainerParser.php | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/phpunit/src/AssignTest.php b/phpunit/src/AssignTest.php index cf44bdb5..62511fb8 100644 --- a/phpunit/src/AssignTest.php +++ b/phpunit/src/AssignTest.php @@ -11,4 +11,12 @@ class AssignTest extends \BaseTest { $this->exec('Cannot re-assign typed object `$obj1` from `stdClass` to `ArrayObject`', 're-assign-2.php'); } + + public function testStdContainerStaticClassMismatch() + { + $this->exec( + 'Cannot assign object of class `StdContainerStaticChild` to std container value of class `StdContainerStaticBase`', + 'std-container-static-class-mismatch.php' + ); + } } diff --git a/src/Php/Parser/StdContainerParser.php b/src/Php/Parser/StdContainerParser.php index 616ba7bb..708fb926 100644 --- a/src/Php/Parser/StdContainerParser.php +++ b/src/Php/Parser/StdContainerParser.php @@ -339,10 +339,9 @@ trait StdContainerParser if ($rightClass !== $class) { $this->fatalError($expr, "Cannot assign object of class `{$rightClass}` to std container value of class `{$class}`"); } - return $this->convertObjectExpr($valueExpr); } - return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class). ', true)'; + return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class) . ', true)'; } protected function parseStdMapKeyType(NodeAbstract $expr, string $owner): string