Skip to content

Commit 9dc4a5a

Browse files
committed
Fix property inconsistency with generics
1 parent 1f150cc commit 9dc4a5a

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ private function processStmtNode(
651651
$throwPoints = [];
652652
$impurePoints = [];
653653
$this->processAttributeGroups($stmt, $stmt->attrGroups, $scope, $nodeCallback);
654-
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->getPhpDocs($scope, $stmt);
654+
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->getPhpDocs($scope, $stmt);
655655

656656
foreach ($stmt->params as $param) {
657657
$this->processParamNode($stmt, $param, $scope, $nodeCallback);
@@ -718,7 +718,7 @@ private function processStmtNode(
718718
true,
719719
$isFromTrait,
720720
$param,
721-
false,
721+
$isReadOnly,
722722
$scope->isInTrait(),
723723
$classReflection->isReadOnly(),
724724
false,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Rules\Generics\PropertyVarianceRule;
6+
use PHPStan\Rules\Generics\VarianceCheck;
7+
use PHPStan\Rules\Rule;
8+
use PHPStan\Testing\RuleTestCase;
9+
10+
/**
11+
* @extends RuleTestCase<PropertyVarianceRule>
12+
*/
13+
class Bug13049Test extends RuleTestCase
14+
{
15+
16+
protected function getRule(): Rule
17+
{
18+
return new PropertyVarianceRule(new VarianceCheck());
19+
}
20+
21+
public function testRule(): void
22+
{
23+
$this->analyse([__DIR__ . '/data/bug-13049.php'], []);
24+
}
25+
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug13049;
6+
7+
/**
8+
* @template-covariant Value of string|list<string>
9+
*
10+
* @immutable
11+
*/
12+
final class LanguageProperty
13+
{
14+
15+
/** @var Value */
16+
public $value;
17+
18+
/**
19+
* @param Value $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
}
26+
27+
/**
28+
* @template-covariant Value of string|list<string>
29+
*
30+
* @immutable
31+
*/
32+
final class LanguageProperty2
33+
{
34+
/**
35+
* @param Value $value
36+
*/
37+
public function __construct(public $value)
38+
{
39+
$this->value = $value;
40+
}
41+
}

0 commit comments

Comments
 (0)