We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Interface method's docblock is not inherited properly with generics in this case: https://psalm.dev/r/dd85197efc
Copy-pasting the entire doc-comment onto Collection::toArray() fixes this, but that's not ideal: https://psalm.dev/r/f7036c58c3
Collection::toArray()
For comparison, it works as-is in PHPStan: https://phpstan.org/r/2185731e-afd0-4e07-905a-33908ee99f6a
The text was updated successfully, but these errors were encountered:
I found these snippets:
<?php declare(strict_types=1); /** * @template-covariant T */ interface ReadableList { /** * @return list<T> */ function toArray(): array; } /** * @template T * @implements ReadableList<T> * @psalm-consistent-constructor */ class Collection implements ReadableList { /** * @param list<T> $values */ function __construct(protected array $values = []) {} function toArray(): array { return $this->values; } } /** * @template T of scalar * @extends Collection<T> */ class ScalarList extends Collection { } /** * @param ScalarList<string> $strings * @psalm-suppress UnusedVariable */ function example(ScalarList $strings): void { /** @psalm-check-type $x = list<string> */ $x = $strings->toArray(); }
Psalm output (using commit 08afc45): ERROR: CheckType - 48:2 - Checked variable $x = list<string> does not match $x = list<T:ScalarList as scalar>
<?php declare(strict_types=1); /** * @template-covariant T */ interface ReadableList { /** * @return list<T> */ function toArray(): array; } /** * @template T * @implements ReadableList<T> * @psalm-consistent-constructor */ class Collection implements ReadableList { /** * @param list<T> $values */ function __construct(protected array $values = []) {} /** * (copy-pasted doc-comment) * * @return list<T> */ function toArray(): array { return $this->values; } } /** * @template T of scalar * @extends Collection<T> */ class ScalarList extends Collection { } /** * @param ScalarList<string> $strings * @psalm-suppress UnusedVariable */ function example(ScalarList $strings): void { /** @psalm-check-type $x = list<string> */ $x = $strings->toArray(); }
Psalm output (using commit 08afc45): No issues!
Sorry, something went wrong.
No branches or pull requests
Interface method's docblock is not inherited properly with generics in this case:
https://psalm.dev/r/dd85197efc
Copy-pasting the entire doc-comment onto
Collection::toArray()
fixes this, but that's not ideal:https://psalm.dev/r/f7036c58c3
For comparison, it works as-is in PHPStan:
https://phpstan.org/r/2185731e-afd0-4e07-905a-33908ee99f6a
The text was updated successfully, but these errors were encountered: