-
Notifications
You must be signed in to change notification settings - Fork 668
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
Unnecessary isset
/ array_key_exists
checks not detected
#9759
Labels
Comments
I found these snippets: https://psalm.dev/r/b32581926c<?php
/** @param array{x: int} $a */
function f(array $a): bool {
if (!array_key_exists('x', $a)) {
return false;
}
return true;
}
https://psalm.dev/r/a6dfa404ce<?php
/** @param array{x: int} $a */
function f(array $a): bool {
if (!isset($a['x'])) {
return false;
}
return true;
}
|
Same with "empty" Also in very basic cases: EDIT: some of the issues are caused by the Mixed type latest changed #7663 (was there before though) where the not part is mixed instead of never |
I found these snippets: https://psalm.dev/r/a22cb83a32<?php
function foo( $bar ) : void {
if ( !isset( $bar ) ) {
if ( !isset( $bar ) ) {
}
}
}
|
kkmuffme
added a commit
to kkmuffme/psalm
that referenced
this issue
Nov 18, 2023
revert vimeo#7663 including previous from_docblock Mixed assignments, as the tests required 2 suppressions and created an escape hatch via mixed on higher psalm error levels, where mixed isn't reported, thus hiding potentially fatal bugs. It's still possible to run the validation of docblock docs though: now with 1 @psalm-suppress (instead of 2) and a @var declaration that contains both possible types, to ensure later code won't escape any checks This is also a required preparation to fix some isset issues of vimeo#9759
kkmuffme
added a commit
to kkmuffme/psalm
that referenced
this issue
Nov 18, 2023
revert vimeo#7663 including previous from_docblock Mixed assignments, as the tests required 2 suppressions and created an escape hatch via mixed on higher psalm error levels, where mixed isn't reported, thus hiding potentially fatal bugs. It's still possible to run the validation of docblock docs though: a @var declaration that contains both possible types, to ensure later code won't escape any checks (and no @psalm-suppress needed at all) This is also a required preparation to fix some isset issues of vimeo#9759
kkmuffme
added a commit
to kkmuffme/psalm
that referenced
this issue
Nov 18, 2023
revert vimeo#7663 including previous from_docblock Mixed assignments, as the tests required 2 suppressions and created an escape hatch via mixed on higher psalm error levels, where mixed isn't reported, thus hiding potentially fatal bugs. It's still possible to run the validation of docblock docs though: a @var declaration that contains both possible types, to ensure later code won't escape any checks (and no @psalm-suppress needed at all) This is also a required preparation to fix some isset issues of vimeo#9759
kkmuffme
added a commit
to kkmuffme/psalm
that referenced
this issue
Nov 21, 2023
revert vimeo#7663 including previous from_docblock Mixed assignments, as the tests required 2 suppressions and created an escape hatch via mixed on higher psalm error levels, where mixed isn't reported, thus hiding potentially fatal bugs. It's still possible to run the validation of docblock docs though: a @var declaration that contains both possible types, to ensure later code won't escape any checks (and no @psalm-suppress needed at all) This is also a required preparation to fix some isset issues of vimeo#9759
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the examples below the property
x
always exists, thus the check is redundant and psalm should give a warning.https://psalm.dev/r/b32581926c
https://psalm.dev/r/a6dfa404ce
The text was updated successfully, but these errors were encountered: