Skip to content
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

Null coalescing assignment operator in if condition does not remove null from type #11158

Open
M393 opened this issue Nov 14, 2024 · 1 comment

Comments

@M393
Copy link

M393 commented Nov 14, 2024

https://psalm.dev/r/cdff4f688e
All three functions should be without a warning as they all behave the same.

Copy link

I found these snippets:

https://psalm.dev/r/cdff4f688e
<?php
function f(): object|null {
    return null;
}
function a(object|null $s): object {
    if (!($s ??= f())) {
        exit;
    }
    return $s;
}
function b(object|null $s): object {
    if (!$s && !($s = f())) {
        exit;
    }
    return $s;
}
function c(object|null $s): object {
    $s ??= f();
    if (!$s) {
        exit;
    }
    return $s;
}
Psalm output (using commit 03ee02c):

ERROR: NullableReturnStatement - 9:12 - The declared return type 'object' for a is not nullable, but the function returns 'null|object'

ERROR: InvalidNullableReturnType - 5:29 - The declared return type 'object' for a is not nullable, but 'null|object' contains null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant