Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3382,9 +3382,19 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,

$exprString = $this->getNodeKey($expr);
$expressionTypes = $scope->expressionTypes;
$expressionTypes[$exprString] = new ExpressionTypeHolder($expr, $type, $certainty);
$newHolder = new ExpressionTypeHolder($expr, $type, $certainty);
$nativeTypes = $scope->nativeExpressionTypes;
$nativeTypes[$exprString] = new ExpressionTypeHolder($expr, $nativeType, $certainty);
$newNativeHolder = new ExpressionTypeHolder($expr, $nativeType, $certainty);

if (
!isset($scope->expressionTypes[$exprString])
|| !isset($scope->nativeExpressionTypes[$exprString])
|| !$newHolder->equals($scope->expressionTypes[$exprString])
|| !$newNativeHolder->equals($scope->nativeExpressionTypes[$exprString])
) {
$expressionTypes[$exprString] = $newHolder;
$nativeTypes[$exprString] = $newNativeHolder;
Comment on lines +3395 to +3396
Copy link
Contributor Author

@staabm staabm Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the same test-errors no matter whether I re-use the whole $scope, or just the ExpressionTypeHolder. need to debug it further.

interessting test errors are:

PHPStan\Rules\Classes\ImpossibleInstanceOfRuleTest::testNewIsAlwaysFinalClass
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '17: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
-33: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
-43: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
-53: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
-63: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
 73: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar|null and ImpossibleInstanceofNewIsAlwaysFinal\Foo will always evaluate to false.
 88: Instanceof between ImpossibleInstanceofNewIsAlwaysFinal\Bar|null and ImpossibleInstanceofNewIsAlwaysFinal\Baz will always evaluate to false.
 '

/Users/staabm/workspace/phpstan-src/src/Testing/RuleTestCase.php:236
/Users/staabm/workspace/phpstan-src/tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php:529

}

$scope = $this->scopeFactory->create(
$this->context,
Expand Down
Loading