vimeo/psalm

instanceof redundant for class, but not for interface

開放

#7,341 建立於 2022年1月8日

 (4 則留言) (0 個反應) (0 位負責人)PHP (668 個分叉)batch import
Help wantedbug

倉庫指標

星標
 (5,369 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南