From 275ef95da7e34562c444ba7d70d456cd3d540621 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 1 Jun 2026 17:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20resolveExprType=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AA=E4=BD=BF=E7=94=A8=20detect?= =?UTF-8?q?TypeOfExpr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/CompilerBase.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index fcc31613..bd59fa7f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -695,8 +695,10 @@ class CompilerBase extends \PhpAot\Core\Translator case 'Scalar_Int': case 'Scalar_Float': case 'Scalar_String': + return $this->parseIdentifier($expr); case 'Expr_Variable': $varName = $this->parseIdentifier($expr); + $this->requireVar($expr, $varName); if ($this->isStdContainer($varName)) { return $varName . '_ref'; } @@ -813,17 +815,6 @@ class CompilerBase extends \PhpAot\Core\Translator return self::TYPE_VAR; } - /** - * Resolve the type of an arbitrary expression for universal method call dispatch. - * Delegates to detectTypeOfExpr — returns null when the type cannot be determined - * at compile time (i.e. detectTypeOfExpr returns TYPE_VAR). - */ - protected function resolveExprType(Node\Expr $expr): ?string - { - $type = $this->detectTypeOfExpr($expr); - return $type !== self::TYPE_VAR ? $type : null; - } - /** * Resolve the ClassDef for an object expression (variable or $this). */ @@ -5434,8 +5425,8 @@ class CompilerBase extends \PhpAot\Core\Translator // 表达式返回值也可使用内置方法:fn()->method(), $obj->fn()->method(), Foo::fn()->method(), $obj->prop->method() if (!$this->isVarExpr($expr->var) and $this->isNamedMethod($expr->name)) { - $type = $this->resolveExprType($expr->var); - if ($type !== null and !$this->checkArgType($type, self::TYPE_OBJECT)) { + $type = $this->detectTypeOfExpr($expr->var); + if ($type !== self::TYPE_VAR && !$this->checkArgType($type, self::TYPE_OBJECT)) { $methodName = $expr->name->toString(); $fn = $this->findUniversalMethodAnyType($type, $methodName); if ($fn) {