Skip to content

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

@javer

Description

@javer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions