Skip to content

Commit

Permalink
Merge pull request #6963 from ptomulik/issue-6937
Browse files Browse the repository at this point in the history
Attempt to fix #6937
  • Loading branch information
orklah committed Nov 23, 2021
2 parents eca56c0 + a7b9a24 commit e8a8055
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Expand Up @@ -964,6 +964,15 @@ private static function compareMethodDocblockReturnTypes(
$guide_method_storage_return_type,
$codebase
);

if ($implementer_method_storage->defining_fqcln) {
self::transformTemplates(
$implementer_classlike_storage->template_extended_params,
$implementer_method_storage->defining_fqcln,
$implementer_method_storage_return_type,
$codebase
);
}
}

if ($implementer_classlike_storage->is_trait) {
Expand Down
64 changes: 64 additions & 0 deletions tests/ReturnTypeTest.php
Expand Up @@ -1002,6 +1002,37 @@ function a($end): void{
}
}'
],
'returnTypeOfAbstractAndConcreteMethodFromTemplatedTraits' => [
'<?php
/** @template T */
trait ImplementerTrait {
/** @var T */
private $value;
/** @psalm-return T */
public function getValue() {
return $this->value;
}
}
/** @template T */
trait GuideTrait {
/** @psalm-return T */
abstract public function getValue();
}
class Test {
/** @use ImplementerTrait<int> */
use ImplementerTrait;
/** @use GuideTrait<int> */
use GuideTrait;
public function __construct() {
$this->value = 123;
}
}'
]
];
}

Expand Down Expand Up @@ -1435,6 +1466,39 @@ function f(): object {
',
'error_message' => 'LessSpecificReturnStatement',
],
'lessSpecificImplementedReturnTypeFromTemplatedTraitMethod' => [
'<?php
/** @template T */
trait ImplementerTrait {
/** @var T */
private $value;
/** @psalm-return T */
public function getValue() {
return $this->value;
}
}
/** @template T */
trait GuideTrait {
/** @psalm-return T */
abstract public function getValue();
}
/** @template T */
class Test {
/** @use ImplementerTrait<T> */
use ImplementerTrait;
/** @use GuideTrait<int> */
use GuideTrait;
public function __construct() {
$this->value = 123;
}
}',
'error_message' => 'LessSpecificImplementedReturnType',
]
];
}
}

0 comments on commit e8a8055

Please sign in to comment.