From 1111cc0c27b90953f6bb28896d493ac5dcbe3a05 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 5 Jun 2026 19:31:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E8=B5=8B=E5=80=BC=E8=A1=A8=E8=BE=BE=E5=BC=8F=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取变量类型获取逻辑到局部变量以提高可读性 - 移除冗余的类型检查转换逻辑 - 简化赋值操作中的类型处理流程 - 保持原有的类型推断功能不变 - 改进代码结构以增强维护性 --- src/Php/Parser/AssignOpTrait.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Php/Parser/AssignOpTrait.php b/src/Php/Parser/AssignOpTrait.php index ac1e8690..3594bf74 100644 --- a/src/Php/Parser/AssignOpTrait.php +++ b/src/Php/Parser/AssignOpTrait.php @@ -236,7 +236,8 @@ trait AssignOpTrait $finalVarType = $this->isNativeType($type) ? $this->getNativeType($type) : $type; $this->addLocalVar($var, $finalVarType); } else { - $this->checkVarAssignExpr($left, $this->getVarType($var), $type); + $finalVarType = $this->getVarType($var); + $this->checkVarAssignExpr($left, $finalVarType, $type); } } } elseif ($this->isPropertyFetch($left) and !$left->getAttribute('nativeProperty')) { @@ -252,17 +253,6 @@ trait AssignOpTrait return $this->parseAssignArrayDim($left, $right); } - // When the RHS is untyped (TYPE_VAR) but the LHS variable already has a known - // native type, use the LHS type for the conversion so that e.g. - // php::Int i; ... i = n; (n is php::Var) - // becomes i = php::toInt(n); - if ($finalVarType === self::TYPE_VAR && $this->hasVar($var)) { - $varType = $this->getVarType($var); - if ($varType !== self::TYPE_VAR) { - $finalVarType = $varType; - } - } - $rightExpr = $this->parseAssignRightExpr($right); $leftExprType = $this->detectTypeOfExpr($left); $rightExprType = $this->detectTypeOfExpr($right);