-
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
Cannot detect check for null when assigning to a variable #3631
Labels
Comments
I found these snippets: https://psalm.dev/r/c9ebe1f843<?php
function takesAString(string $name): void {
echo "hello: ".$name;
}
function randomReturn(): ?string {
return rand(1,2) === 1 ? 'foo' : null;
}
$name = randomReturn();
// This comparison works file
if ($name !== null) {
takesAString($name);
}
// Adding comparison to variable does not work
$hasStringValue = $name !== null;
if ($hasStringValue) {
takesAString($name);
}
// Assignment in if does not work
if ($hasStringValue = $name !== null) {
takesAString($name);
}
|
Generally if it works in TypeScript it should work in Psalm, and the example in this ticket works in TypeScript (so it now works in Psalm too). The other example in the link doesn't work in Psalm, as it would require some pretty complex analysis:
|
Lovely. Thank you for a quick fix. |
muglug
added a commit
that referenced
this issue
Jun 23, 2020
The fix caused a regression so I'm unfixing for now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this bug. Not sure if it is "too complex" or not. I just thought to report it.
https://psalm.dev/r/c9ebe1f843
The text was updated successfully, but these errors were encountered: