Skip to content

Fix Promoted vs. regular property inconsistency with generics #4157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -718,7 +718,7 @@ private function processStmtNode(
true,
$isFromTrait,
$param,
false,
$isReadOnly,
$scope->isInTrait(),
$classReflection->isReadOnly(),
false,
Expand Down
26 changes: 26 additions & 0 deletions tests/PHPStan/Analyser/Bug13049Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Rules\Generics\PropertyVarianceRule;
use PHPStan\Rules\Generics\VarianceCheck;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;

/**
* @extends RuleTestCase<PropertyVarianceRule>
*/
class Bug13049Test extends RuleTestCase
{

protected function getRule(): Rule
{
return new PropertyVarianceRule(new VarianceCheck());
Copy link
Member

Choose a reason for hiding this comment

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

The fix is great, but please put this into existing PropertyVarianceRuleTest instead of adding a new test case. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!
I fixed in 4e32f77.

}

public function testRule(): void
{
$this->analyse([__DIR__ . '/data/bug-13049.php'], []);
}

}
41 changes: 41 additions & 0 deletions tests/PHPStan/Analyser/data/bug-13049.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug13049;

/**
* @template-covariant Value of string|list<string>
*
* @immutable
*/
final class LanguageProperty
{

/** @var Value */
public $value;

/**
* @param Value $value
*/
public function __construct($value)
{
$this->value = $value;
}
}

/**
* @template-covariant Value of string|list<string>
*
* @immutable
*/
final class LanguageProperty2
{
/**
* @param Value $value
*/
public function __construct(public $value)
{
$this->value = $value;
}
}
Loading