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

Invalid "evaluates to false" with generics + inheritance #6591

Closed
internalsystemerror opened this issue Feb 7, 2022 · 2 comments
Closed
Labels
Milestone

Comments

@internalsystemerror
Copy link

internalsystemerror commented Feb 7, 2022

Bug report

When checking for a child of a child interface, an invalid error is shown that the statement will always evaluate to false. This may be related to #5869 and is introduced in 1.4.6.

Code snippet that reproduces the problem

Demo: https://phpstan.org/r/23d7c262-5ae8-4fff-aa24-687f404aede0

Excerpt:

interface EntityInterface {...}
interface UpdatableInterface extends EntityInterface {...}
interface EnableableInterface extends UpdatableInterface {...}

public function extract(object $object): array
{
    ...
    if ($object instanceof EnableableInterface) {
        $data[EnableableInterface::ENABLED] = $object->isEnabled();
    }
    ...
}

public function hydrate(array $data, object $object): EntityInterface
{
    ...
    if ($object instanceof EnableableInterface) {
        $object->setEnabled($data[EnableableInterface::ENABLED]);
    }
    ...
}

gives:

53 | Instanceof between T of EntityInterface and EnableableInterface will always evaluate to false.
75 | Instanceof between T of EntityInterface and EnableableInterface will always evaluate to false.

Expected output

No error

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

PHPStan helps me every day.

@ondrejmirtes ondrejmirtes added this to the Generics milestone Feb 10, 2022
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@51e2df3

@github-actions
Copy link

github-actions bot commented Apr 9, 2022

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 Apr 9, 2022
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