Repository navigation
TypeGuess::getBestGuess expects array<array-key, TypeGuess&static>, parent type array{TypeGuess} provided #5937
Answered
by
weirdan
VincentLanglet
asked this question in
Q&A
|
I simplified the use of this method: https://github.com/symfony/form/blob/5.3/Guess/Guess.php#L67 https://psalm.dev/r/3765f8a43d I'm getting I don't understand the error, the static phpdoc is unclear to me. Is my example wrong or should the symfony phpdoc be updated ? |
Answered by
weirdan
Jun 16, 2021
Replies: 1 comment 1 reply
|
Looks like a bug to me. The issue emitted there is basically preventing you from doing this (unsafe as <?php
abstract class Guess {
/**
* @param static[] $guesses An array of guesses
*
* @return static|null
*/
public function getBestGuess(array $guesses) {
return $guesses[0] ?? null;
}
}
class A extends Guess {}
class B extends Guess {}
class FooFoo {
public function guess(Guess $a, Guess $b): ?Guess {
return $a->getBestGuess([$b]);
}
}However in your case we know exactly what class |
1 reply
Answer selected by
VincentLanglet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like a bug to me. The issue emitted there is basically preventing you from doing this (unsafe as
$aand$bdo not necessarily receive objects of the same class): https://psalm.dev/r/9e18c10edcHowever in your case we know exactly what class
staticrefers to (as it's a static call), and it's gi…