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

Wrong not-null type after using null coalescing operator with nullsafe property access #8517

Closed
javer opened this issue Dec 13, 2022 · 2 comments
Labels
Milestone

Comments

@javer
Copy link

javer commented Dec 13, 2022

Bug report

Using null coalescing operator in the expression wrongly makes the first operand not-nullable, see type change between lines 7-10 and no type change between lines 5-7.

The false positive occurs when using something like:

$routeParams = $request?->attributes->get('_route_params', []) ?? [];

and don't occur when using:

$routeParams = $request?->attributes->get('_route_params', []);

Code snippet that reproduces the problem

https://phpstan.org/r/e71669b3-f8e3-43e9-bf54-08d6fd2bb9fd

Expected output

Reading a nullable value shouldn't make it not-nullable even when null coalescing operator is used.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2577

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants