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

[Bug] Doesn't work well with null-safe operator #9465

Closed
faizanakram99 opened this issue Mar 7, 2023 · 2 comments
Closed

[Bug] Doesn't work well with null-safe operator #9465

faizanakram99 opened this issue Mar 7, 2023 · 2 comments

Comments

@faizanakram99
Copy link

Both functions takesMaybeFoo and takesMaybeFooBuggy are functionally the same, the former is ok, the latter throws a couple of errors.

https://psalm.dev/r/a28247a9bc

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/a28247a9bc
<?php

class foo
{
    public ?string $prop = null;
}

function takesMaybeFoo(?foo $foo): void
{
    if (null === $foo || null === $foo->prop) {
		return;
	}
       
    takesString($foo->prop);
}


function takesMaybeFooBuggy(?foo $foo): void
{
    if (null === $foo?->prop) {
		return;
	}
       
    takesString($foo->prop);
}

function takesString(string $str): string
{
    return $str;
}
Psalm output (using commit c82191b):

ERROR: PossiblyNullPropertyFetch - 24:17 - Cannot get property on possibly null variable $foo of type foo|null

ERROR: PossiblyNullArgument - 24:17 - Argument 1 of takesString cannot be null, possibly null value provided

@faizanakram99
Copy link
Author

duplicates #5873

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