vimeo/psalm

instanceof redundant for class, but not for interface

Open

#7 341 ouverte le 8 janv. 2022

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)PHP (668 forks)batch import
Help wantedbug

Métriques du dépôt

Stars
 (5 369 stars)
Métriques de merge PR
 (Merge moyen 3j 12h) (5 PRs mergées en 30 j)

Description

psalm is inconsistent in when it says "RedundantCondition" on instanceof checks.

https://psalm.dev/r/377cb86ce7

interface I {}
class C {}

/**
 * @param I $o
 */
function fI(I $o): void {
    // Not redundant?
    if ($o instanceof I) {
        print 'yes';
    }
}

/**
 * @param C $o
 */
function fC(C $o): void {
    // ERROR: RedundantCondition - 20:9 - Type C for $o is always C
    if ($o instanceof C) {
        print 'yes';
    }
}

Guide contributeur