Skip to content

TypeGuess::getBestGuess expects array<array-key, TypeGuess&static>, parent type array{TypeGuess} provided #5937

Answered by weirdan
VincentLanglet asked this question in Q&A
Discussion options

You must be logged in to vote

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/9e18c10edc

<?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 static refers to (as it's a static call), and it's gi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@VincentLanglet
Comment options

Answer selected by VincentLanglet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants