@@ -1643,45 +1643,24 @@ private function findTypeExpressionsFromBinaryOperation(Scope $scope, Node\Expr\
16431643 $ leftType = $ scope ->getType ($ binaryOperation ->left );
16441644 $ rightType = $ scope ->getType ($ binaryOperation ->right );
16451645
1646- $ rightExpr = $ this ->extractExpression ($ binaryOperation ->right );
1647- $ leftExpr = $ this ->extractExpression ($ binaryOperation ->left );
1648-
1649- if (
1650- $ leftType instanceof ConstantScalarType
1651- && !$ rightExpr instanceof ConstFetch
1652- && !$ rightExpr instanceof ClassConstFetch
1653- ) {
1654- return [$ binaryOperation ->right , $ leftType , $ rightType ];
1655- } elseif (
1656- $ rightType instanceof ConstantScalarType
1657- && !$ leftExpr instanceof ConstFetch
1658- && !$ leftExpr instanceof ClassConstFetch
1659- ) {
1660- return [$ binaryOperation ->left , $ rightType , $ leftType ];
1646+ $ rightExpr = $ binaryOperation ->right ;
1647+ if ($ rightExpr instanceof AlwaysRememberedExpr) {
1648+ $ rightExpr = $ rightExpr ->getExpr ();
16611649 }
16621650
1663- return null ;
1664- }
1665-
1666- /**
1667- * @return array{Expr, Type, Type}|null
1668- */
1669- private function findEnumTypeExpressionsFromBinaryOperation (Scope $ scope , Node \Expr \BinaryOp $ binaryOperation ): ?array
1670- {
1671- $ leftType = $ scope ->getType ($ binaryOperation ->left );
1672- $ rightType = $ scope ->getType ($ binaryOperation ->right );
1673-
1674- $ rightExpr = $ this ->extractExpression ($ binaryOperation ->right );
1675- $ leftExpr = $ this ->extractExpression ($ binaryOperation ->left );
1651+ $ leftExpr = $ binaryOperation ->left ;
1652+ if ($ leftExpr instanceof AlwaysRememberedExpr) {
1653+ $ leftExpr = $ leftExpr ->getExpr ();
1654+ }
16761655
16771656 if (
1678- $ leftType-> getEnumCases () === [ $ leftType ]
1657+ $ leftType instanceof ConstantScalarType
16791658 && !$ rightExpr instanceof ConstFetch
16801659 && !$ rightExpr instanceof ClassConstFetch
16811660 ) {
16821661 return [$ binaryOperation ->right , $ leftType , $ rightType ];
16831662 } elseif (
1684- $ rightType-> getEnumCases () === [ $ rightType ]
1663+ $ rightType instanceof ConstantScalarType
16851664 && !$ leftExpr instanceof ConstFetch
16861665 && !$ leftExpr instanceof ClassConstFetch
16871666 ) {
@@ -1691,11 +1670,6 @@ private function findEnumTypeExpressionsFromBinaryOperation(Scope $scope, Node\E
16911670 return null ;
16921671 }
16931672
1694- private function extractExpression (Expr $ expr ): Expr
1695- {
1696- return $ expr instanceof AlwaysRememberedExpr ? $ expr ->getExpr () : $ expr ;
1697- }
1698-
16991673 /** @api */
17001674 public function create (
17011675 Expr $ expr ,
@@ -2087,27 +2061,6 @@ public function resolveEqual(Expr\BinaryOp\Equal $expr, Scope $scope, TypeSpecif
20872061 ) {
20882062 return $ this ->specifyTypesInCondition ($ scope , new Expr \BinaryOp \Identical ($ expr ->left , $ expr ->right ), $ context )->setRootExpr ($ expr );
20892063 }
2090-
2091- if (!$ context ->null () && TypeCombinator::containsNull ($ otherType )) {
2092- if ($ constantType ->toBoolean ()->isTrue ()->yes ()) {
2093- $ otherType = TypeCombinator::remove ($ otherType , new NullType ());
2094- }
2095-
2096- if (!$ otherType ->isSuperTypeOf ($ constantType )->no ()) {
2097- return $ this ->create ($ exprNode , TypeCombinator::intersect ($ constantType , $ otherType ), $ context , $ scope )->setRootExpr ($ expr );
2098- }
2099- }
2100- }
2101-
2102- $ expressions = $ this ->findEnumTypeExpressionsFromBinaryOperation ($ scope , $ expr );
2103- if ($ expressions !== null ) {
2104- $ exprNode = $ expressions [0 ];
2105- $ enumCaseObjectType = $ expressions [1 ];
2106- $ otherType = $ expressions [2 ];
2107-
2108- if (!$ context ->null ()) {
2109- return $ this ->create ($ exprNode , TypeCombinator::intersect ($ enumCaseObjectType , $ otherType ), $ context , $ scope )->setRootExpr ($ expr );
2110- }
21112064 }
21122065
21132066 $ leftType = $ scope ->getType ($ expr ->left );
0 commit comments