Skip to content

Commit

Permalink
attempt to fix vimeo#6937
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomulik committed Nov 22, 2021
1 parent cd8ba5c commit e6bcbb2
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 AggregateTrait {
/** @var T */
private $value;
/** @psalm-return T */
public function getValue() {
return $this->value;
}
}
/** @template T */
trait AnotherTrait {
/** @psalm-return T */
abstract public function getValue();
}
class Test {
/** @use AggregateTrait<int> */
use AggregateTrait;
/** @use AnotherTrait<int> */
use AnotherTrait;
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 AggregateTrait {
/** @var T */
private $value;
/** @psalm-return T */
public function getValue() {
return $this->value;
}
}
/** @template T */
trait AnotherTrait {
/** @psalm-return T */
abstract public function getValue();
}
/** @template T */
class Test {
/** @use AggregateTrait<T> */
use AggregateTrait;
/** @use AnotherTrait<int> */
use AnotherTrait;
public function __construct() {
$this->value = 123;
}
}',
'error_message' => 'LessSpecificImplementedReturnType',
]
];
}
}

0 comments on commit e6bcbb2

Please sign in to comment.