-
Notifications
You must be signed in to change notification settings - Fork 661
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
RedundantCondition when asserting exception sub-class #4473
Comments
Cannot reproduce it on psalm.dev I'm afraid. |
Running the above doesn't reproduce the stated issue |
Actually here's a simple reproducer: https://psalm.dev/r/6d85680f44 |
I found these snippets: https://psalm.dev/r/6d85680f44<?php declare(strict_types = 1);
/**
* @param mixed $value
* @param class-string<T> $type
* @template T
* @psalm-assert T $value
*/
function assertInstanceOf($value, string $type): void {
// some code
}
class E {}
/** @param class-string<E> $e_class */
function foo(string $e_class, E $some_e) : void {
assertInstanceOf($some_e, $e_class);
}
|
Actually this is an issue with PHPUnit's assertion – it should be Please open a ticket in PHPUnit's repo! |
I found these snippets: https://psalm.dev/r/c02c5ac41f<?php declare(strict_types = 1);
/**
* @param mixed $value
* @param class-string<T> $type
* @template T
* @psalm-assert =T $value
*/
function assertInstanceOf($value, string $type): void {
// some code
}
class E {}
/** @param class-string<E> $e_class */
function foo(string $e_class, E $some_e) : void {
assertInstanceOf($some_e, $e_class);
}
|
Thanks a lot, @muglug! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While creating doctrine/dbal#4401, I noticed that Psalm complains in the following (simplified) case:
As far as I can see, the condition is not redundant: while
$dbalException
is aDriverException
, there is no guarantee that it passes theinstanceof
check for the subclass ofDriverException
provided.Full reproducer:
git clone https://github.com/BenMorel/dbal.git cd dbal git checkout unused-var composer install vendor/bin/psalm
The text was updated successfully, but these errors were encountered: