|
18 | 18 | use PhpParser\Node\Expr\StaticCall;
|
19 | 19 | use PhpParser\Node\Expr\StaticPropertyFetch;
|
20 | 20 | use PhpParser\Node\Name;
|
| 21 | +use PHPStan\Node\Expr\AlwaysRememberedExpr; |
21 | 22 | use PHPStan\Node\Printer\ExprPrinter;
|
22 | 23 | use PHPStan\Reflection\Assertions;
|
23 | 24 | use PHPStan\Reflection\ParametersAcceptor;
|
@@ -191,24 +192,33 @@ public function specifyTypesInCondition(
|
191 | 192 | }
|
192 | 193 | }
|
193 | 194 |
|
194 |
| - $rightType = $scope->getType($expr->right); |
| 195 | + $rightExpr = $expr->right; |
| 196 | + if ($rightExpr instanceof AlwaysRememberedExpr) { |
| 197 | + $rightExpr = $rightExpr->getExpr(); |
| 198 | + } |
| 199 | + |
| 200 | + $leftExpr = $expr->left; |
| 201 | + if ($leftExpr instanceof AlwaysRememberedExpr) { |
| 202 | + $leftExpr = $leftExpr->getExpr(); |
| 203 | + } |
| 204 | + $rightType = $scope->getType($rightExpr); |
195 | 205 | if (
|
196 |
| - $expr->left instanceof ClassConstFetch && |
197 |
| - $expr->left->class instanceof Expr && |
198 |
| - $expr->left->name instanceof Node\Identifier && |
199 |
| - $expr->right instanceof ClassConstFetch && |
| 206 | + $leftExpr instanceof ClassConstFetch && |
| 207 | + $leftExpr->class instanceof Expr && |
| 208 | + $leftExpr->name instanceof Node\Identifier && |
| 209 | + $rightExpr instanceof ClassConstFetch && |
200 | 210 | $rightType instanceof ConstantStringType &&
|
201 |
| - strtolower($expr->left->name->toString()) === 'class' |
| 211 | + strtolower($leftExpr->name->toString()) === 'class' |
202 | 212 | ) {
|
203 | 213 | return $this->specifyTypesInCondition(
|
204 | 214 | $scope,
|
205 | 215 | new Instanceof_(
|
206 |
| - $expr->left->class, |
| 216 | + $leftExpr->class, |
207 | 217 | new Name($rightType->getValue()),
|
208 | 218 | ),
|
209 | 219 | $context,
|
210 | 220 | $rootExpr,
|
211 |
| - ); |
| 221 | + )->unionWith($this->create($expr->left, $rightType, $context, false, $scope, $rootExpr)); |
212 | 222 | }
|
213 | 223 | if ($context->false()) {
|
214 | 224 | $identicalType = $scope->getType($expr);
|
@@ -1420,16 +1430,27 @@ private function findTypeExpressionsFromBinaryOperation(Scope $scope, Node\Expr\
|
1420 | 1430 | {
|
1421 | 1431 | $leftType = $scope->getType($binaryOperation->left);
|
1422 | 1432 | $rightType = $scope->getType($binaryOperation->right);
|
| 1433 | + |
| 1434 | + $rightExpr = $binaryOperation->right; |
| 1435 | + if ($rightExpr instanceof AlwaysRememberedExpr) { |
| 1436 | + $rightExpr = $rightExpr->getExpr(); |
| 1437 | + } |
| 1438 | + |
| 1439 | + $leftExpr = $binaryOperation->left; |
| 1440 | + if ($leftExpr instanceof AlwaysRememberedExpr) { |
| 1441 | + $leftExpr = $leftExpr->getExpr(); |
| 1442 | + } |
| 1443 | + |
1423 | 1444 | if (
|
1424 | 1445 | $leftType instanceof ConstantScalarType
|
1425 |
| - && !$binaryOperation->right instanceof ConstFetch |
1426 |
| - && !$binaryOperation->right instanceof ClassConstFetch |
| 1446 | + && !$rightExpr instanceof ConstFetch |
| 1447 | + && !$rightExpr instanceof ClassConstFetch |
1427 | 1448 | ) {
|
1428 | 1449 | return [$binaryOperation->right, $leftType];
|
1429 | 1450 | } elseif (
|
1430 | 1451 | $rightType instanceof ConstantScalarType
|
1431 |
| - && !$binaryOperation->left instanceof ConstFetch |
1432 |
| - && !$binaryOperation->left instanceof ClassConstFetch |
| 1452 | + && !$leftExpr instanceof ConstFetch |
| 1453 | + && !$leftExpr instanceof ClassConstFetch |
1433 | 1454 | ) {
|
1434 | 1455 | return [$binaryOperation->left, $rightType];
|
1435 | 1456 | }
|
|
0 commit comments