Skip to content

Narrowing a type by extending loses information of parent #11364

@BackEndTea

Description

@BackEndTea

Bug report

When a method has a return type, which gets narrowed in the child class, any information from the parent seems to be lost.

I think that this could be solved by making a child return type an intersection between its return type and that of the parent?

Code snippet that reproduces the problem

https://phpstan.org/r/9d725389-4e11-4b53-aa3f-df765c811e21

Expected output

I'd expect the dumped types to be array<string> for the Fail class, and array<string>|(callable(): array<string>) for the Good class (which already works).

And there should be no error for Fail::check.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions