TypeGuess::getBestGuess expects array<array-key, TypeGuess&static>, parent type array{TypeGuess} provided #5937
-
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 ? |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
Looks like a bug to me. The issue emitted there is basically preventing you from doing this (unsafe as
$a
and$b
do not necessarily receive objects of the same class): https://psalm.dev/r/9e18c10edcHowever in your case we know exactly what class
static
refers to (as it's a static call), and it's gi…