Skip to content

Null-safe operator loses type in loop #9721

@leongersen

Description

@leongersen

Bug report

These expressions should be equivalent (when the result of mergeWith cannot be null):

$mergedExample = $mergedExample !== null ? $mergedExample->mergeWith() : $example;
$mergedExample = $mergedExample?->mergeWith() ?? $example;

The expression with the null safe operator results in mixed for $mergedExample, the ternary expression is analysed correctly.

Code snippet that reproduces the problem

https://phpstan.org/r/a88e69f2-8ca7-471b-beb4-fd427772df0a

Expected output

The dumped type for $mergedExample should be Example.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions