From 9dc4a5ab5d7de92f97aabfd748a0bfdc9862decf Mon Sep 17 00:00:00 2001 From: sayuprc Date: Sat, 26 Jul 2025 00:22:18 +0900 Subject: [PATCH 1/2] Fix property inconsistency with generics --- src/Analyser/NodeScopeResolver.php | 4 +-- tests/PHPStan/Analyser/Bug13049Test.php | 26 ++++++++++++++ tests/PHPStan/Analyser/data/bug-13049.php | 41 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tests/PHPStan/Analyser/Bug13049Test.php create mode 100644 tests/PHPStan/Analyser/data/bug-13049.php diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 8ff656bb57..bbfdb61615 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -651,7 +651,7 @@ private function processStmtNode( $throwPoints = []; $impurePoints = []; $this->processAttributeGroups($stmt, $stmt->attrGroups, $scope, $nodeCallback); - [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->getPhpDocs($scope, $stmt); + [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->getPhpDocs($scope, $stmt); foreach ($stmt->params as $param) { $this->processParamNode($stmt, $param, $scope, $nodeCallback); @@ -718,7 +718,7 @@ private function processStmtNode( true, $isFromTrait, $param, - false, + $isReadOnly, $scope->isInTrait(), $classReflection->isReadOnly(), false, diff --git a/tests/PHPStan/Analyser/Bug13049Test.php b/tests/PHPStan/Analyser/Bug13049Test.php new file mode 100644 index 0000000000..e37a2d94d1 --- /dev/null +++ b/tests/PHPStan/Analyser/Bug13049Test.php @@ -0,0 +1,26 @@ + + */ +class Bug13049Test extends RuleTestCase +{ + + protected function getRule(): Rule + { + return new PropertyVarianceRule(new VarianceCheck()); + } + + public function testRule(): void + { + $this->analyse([__DIR__ . '/data/bug-13049.php'], []); + } + +} diff --git a/tests/PHPStan/Analyser/data/bug-13049.php b/tests/PHPStan/Analyser/data/bug-13049.php new file mode 100644 index 0000000000..86386bc019 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-13049.php @@ -0,0 +1,41 @@ += 8.0 + +declare(strict_types = 1); + +namespace Bug13049; + +/** + * @template-covariant Value of string|list + * + * @immutable + */ +final class LanguageProperty +{ + + /** @var Value */ + public $value; + + /** + * @param Value $value + */ + public function __construct($value) + { + $this->value = $value; + } +} + +/** + * @template-covariant Value of string|list + * + * @immutable + */ +final class LanguageProperty2 +{ + /** + * @param Value $value + */ + public function __construct(public $value) + { + $this->value = $value; + } +} From 4e32f77c7f9fd23d91f2ae705d7c8580230c1dc4 Mon Sep 17 00:00:00 2001 From: sayuprc Date: Thu, 7 Aug 2025 18:27:39 +0900 Subject: [PATCH 2/2] Fix testcase --- tests/PHPStan/Analyser/Bug13049Test.php | 26 ------------------- .../Generics/PropertyVarianceRuleTest.php | 5 ++++ .../Generics}/data/bug-13049.php | 0 3 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 tests/PHPStan/Analyser/Bug13049Test.php rename tests/PHPStan/{Analyser => Rules/Generics}/data/bug-13049.php (100%) diff --git a/tests/PHPStan/Analyser/Bug13049Test.php b/tests/PHPStan/Analyser/Bug13049Test.php deleted file mode 100644 index e37a2d94d1..0000000000 --- a/tests/PHPStan/Analyser/Bug13049Test.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class Bug13049Test extends RuleTestCase -{ - - protected function getRule(): Rule - { - return new PropertyVarianceRule(new VarianceCheck()); - } - - public function testRule(): void - { - $this->analyse([__DIR__ . '/data/bug-13049.php'], []); - } - -} diff --git a/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php b/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php index 8998d9712e..b5aeefa8e9 100644 --- a/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php +++ b/tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php @@ -132,4 +132,9 @@ public function testBug9153(): void $this->analyse([__DIR__ . '/data/bug-9153.php'], []); } + public function testBug13049(): void + { + $this->analyse([__DIR__ . '/data/bug-13049.php'], []); + } + } diff --git a/tests/PHPStan/Analyser/data/bug-13049.php b/tests/PHPStan/Rules/Generics/data/bug-13049.php similarity index 100% rename from tests/PHPStan/Analyser/data/bug-13049.php rename to tests/PHPStan/Rules/Generics/data/bug-13049.php