Skip to content
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

Attempt to fix #6937 #6963

Merged
merged 1 commit into from Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
]
];
}
}