-
Notifications
You must be signed in to change notification settings - Fork 659
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
LessSpecificReturnStatement + MoreSpecificReturnType reported together #2875
Comments
I found these snippets: https://psalm.dev/r/4c0bab583c<?php
class Foo
{
/**
* @psalm-var class-string
* @var string
*/
private $class = Bar::class;
/**
* @return class-string
*/
public function getClass(): string
{
return $this->class;
}
}
interface Baz {}
class Bar implements Baz
{
/**
* @template T
* @psalm-param class-string<T> $class
* @return (Baz&T)|null
*/
public function instantiator(string $class): ?Baz
{
return rand(0, 1) ? new $class() : null;
}
}
$foo = new Foo();
$bar = new Bar();
$bar->instantiator($foo->getClass());
|
Order-dependence is unexpected, but wouldn't it make more sense to declare the types like this: https://psalm.dev/r/462ae2c353 |
I found these snippets: https://psalm.dev/r/462ae2c353<?php
class Foo
{
/**
* @psalm-var class-string
* @var string
*/
private $class = Bar::class;
/**
* @return class-string
*/
public function getClass(): string
{
return $this->class;
}
}
interface Baz {}
class Bar implements Baz
{
/**
* @template T of Baz
* @psalm-param class-string<T> $class
* @return ?T
*/
public function instantiator(string $class): ?Baz
{
return rand(0, 1) ? new $class() : null;
}
}
$foo = new Foo();
$bar = new Bar();
$bar->instantiator($foo->getClass());
|
i wasn't aware of that syntax. thanks |
Yes, order-dependence is still a bug |
seems phpstan doesn't like |
distilled down, these should both be errors: https://psalm.dev/r/7c42967494 |
I found these snippets: https://psalm.dev/r/7c42967494<?php
interface Bar {}
interface Baz {}
/**
* @template T
* @psalm-param class-string<T> $class
* @return T&Baz
*/
function returnsTemplatedIntersection(string $class) {
return new $class();
}
/**
* @return Bar&Baz
*/
function returnsIntersection(Bar $bar) {
return $bar;
}
|
huh, thanks. i got an error. i'll look into it another time. |
See: https://psalm.dev/r/4c0bab583c
If we change line 28 to
@return (T&Baz)|null
(switching Baz and T), then there are no errors.
The text was updated successfully, but these errors were encountered: