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
Wrong inheritance fetching return type #4537
Comments
I found these snippets: https://psalm.dev/r/7f937bb1d0<?php
/**
* @template T
*/
interface A
{
/**
* @template F
* @param F $value
* @return A<F>
*/
public function map($value): A;
}
/**
* @template T
* @template-extends A<T>
*/
interface B extends A
{
/**
* @template F
* @param F $value
* @return B<F>
*/
public function map($value): A;
}
/**
* @template T
* @template-implements B<T>
*/
class Foo implements B
{
/**
* @var T
*/
private $value;
/**
* @param T $value
*/
public function __construct($value)
{
$this->value = $value;
}
public function map($value): A
{
return new Foo($value);
}
}
$foo = new Foo('str');
/** @psalm-trace $value */
$value = $foo->map('string');
|
Simplified without generics: https://psalm.dev/r/d3c5472f7a |
I found these snippets: https://psalm.dev/r/d3c5472f7a<?php
interface A
{
/**
* @return A
*/
public function map(): A;
}
interface B extends A
{
/**
* @return B
*/
public function map(): A;
}
class F implements B
{
public function map(): A {
return new F();
}
}
function takesB(B $f) : B {
return $f->map();
}
function takesF(F $f) : B {
return $f->map();
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same as #4524 but for return types, it seems that return types as not fetched from the right parent class/interface.
I don't know if this is the right example, but debugging I noticed this bug.
https://psalm.dev/r/7f937bb1d0
Since Foo::test() returns Foo, which implements B, which implements A, the signature should be valid.
The text was updated successfully, but these errors were encountered: