Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a39902

Browse files
authored
Fix Promoted vs. regular property inconsistency with generics
1 parent cd6b3fd commit 5a39902

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-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,

‎tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,9 @@ public function testBug9153(): void
132132
$this->analyse([__DIR__ . '/data/bug-9153.php'], []);
133133
}
134134

135+
public function testBug13049(): void
136+
{
137+
$this->analyse([__DIR__ . '/data/bug-13049.php'], []);
138+
}
139+
135140
}
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)

AltStyle によって変換されたページ (->オリジナル) /