Skip to content

PHP 8 match() does not infer type in matched branch #4544

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

Closed
tux-rampage opened this issue Nov 13, 2020 · 1 comment
Closed

PHP 8 match() does not infer type in matched branch #4544

tux-rampage opened this issue Nov 13, 2020 · 1 comment
Labels

Comments

@tux-rampage
Copy link
Contributor

When using get_class in a match() statement, the type is not inferred in the branches causing incorrect analysis errors.

https://psalm.dev/r/ce8e6603c5

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/ce8e6603c5
<?php

interface Foo {}

class Bar implements Foo 
{
    public function hello(): string 
    {
        return 'Hello World';
    }
}

function foo(Foo $value): string {
    return match (get_class($value)) {
        Bar::class => $value->hello(),
        default => 'Some Foo',
    };
}
Psalm output (using commit 5a62dc5):

ERROR: UndefinedInterfaceMethod - 15:31 - Method Foo::hello does not exist

INFO: MixedReturnStatement - 14:12 - Could not infer a return type

INFO: MixedInferredReturnType - 13:27 - Could not verify return type 'string' for foo

@muglug muglug added the bug label Nov 13, 2020
@muglug muglug closed this as completed in 086237a Nov 13, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
danog Daniil Gentili
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants