-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instanceof redundant for class, but not for interface #7341
Comments
I found these snippets: https://psalm.dev/r/377cb86ce7<?php
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';
}
}
|
The difference is here:
In your snippet, it doesn't matter that much, but the RedundantCondition is a false positive because of this: https://psalm.dev/r/3bd23090dd |
I found these snippets: https://psalm.dev/r/3bd23090dd<?php
interface I {}
class C {}
class B extends C{}
class D extends C{}
class A{
/**
* @param C $o
* @param class-string<C> $c
*/
public static function C(C $o, string $c): void {
// ERROR: RedundantCondition - 20:9 - Type C for $o is always C
if ($o instanceof $c) {
print 'yes';
}
}
}
$b = new B();
A::C($b, D::class);
|
I actually worked on a very similar issue very close to this code: #6739 In fact, when dropping the Not sure why there are two conditions |
psalm is inconsistent in when it says "RedundantCondition" on instanceof checks.
https://psalm.dev/r/377cb86ce7
The text was updated successfully, but these errors were encountered: