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
ImplementedReturnTypeMismatch on template trait abstract method #6937
Comments
I found these snippets: https://psalm.dev/r/07c75f40bc<?php
/**
* @psalm-template T
*/
trait AggregateTrait {
/**
* @psalm-readonly
* @var T
*/
private $value;
/**
* @psalm-return T
*/
public function getValue()
{
return $this->value;
}
}
/**
* @psalm-template T
*/
trait AnotherTrait {
/**
* @psalm-return T
*/
abstract public function getValue();
}
/**
* @psalm-template T
*/
class Test {
/**
* @template-use AggregateTrait<T>
*/
use AggregateTrait;
/**
* @template-use AnotherTrait<T>
*/
use AnotherTrait;
/**
* @psalm-param T $value
*/
public function __construct($value) {
$this->value = $value;
}
}
|
Simplified and condensed a bit: https://psalm.dev/r/d6d08bda2f |
I found these snippets: https://psalm.dev/r/d6d08bda2f<?php
/** @psalm-template T */
trait AggregateTrait {
/** @var T */
private $value;
/** @psalm-return T */
public function getValue() {
return $this->value;
}
}
/** @psalm-template T */
trait AnotherTrait {
/** @psalm-return T */
abstract public function getValue();
}
class Test {
/** @template-use AggregateTrait<int> */
use AggregateTrait;
/** @template-use AnotherTrait<int> */
use AnotherTrait;
public function __construct() {
$this->value = 123;
}
}
|
I'd like to try to fix this, where shall I start? |
I usually start with running Psalm on the failing snippet with
|
It looks like MethodComparator::create gets called twice for the above example. It first compares the two traits, then it attempts to compare
I observed that the comparison is successfull as long as the implementer class(like) is a trait. This may also be infered from the code of MethodComparator::compareMethodDocblockReturnType(). If it's not a trait, then ( The question is now, where to dig further to find an solution? |
Two template traits used by a class, one trait declares an abstract method, other implements it. When used, the ImplementedReturnTypeMismatch error is reported.
https://psalm.dev/r/07c75f40bc
The text was updated successfully, but these errors were encountered: