vimeo/psalm

instanceof redundant for class, but not for interface

オープン

#7,341 opened on 2022/01/08

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)PHP (668 件のフォーク)batch import
Help wantedbug

Repository metrics

Stars
 (5,369 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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';
    }
}

コントリビューターガイド