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

Wrong array key type inferring from the result of static method call on class-string #6404

Closed
javer opened this issue Jan 18, 2022 · 2 comments
Labels

Comments

@javer
Copy link

javer commented Jan 18, 2022

Bug report

Array key which is a value of type int returned from static method called on string prechecked by is_a is wrongly treated as int|string in PHPStan 1.4.1 (there was no error in PHPStan 1.3.1):

class Foo {
    public static function getCode(): int {
        return 1;
    }
}

if (is_a($fooClass, Foo::class, true)) {
    $this->someMap[$fooClass::getCode()] = true;
}
Property Bar::$someMap (array<int, bool>) does not accept array<int|string, bool>.

The issue might be related to #6403, but it looks like a little bit different.

Code snippet that reproduces the problem

https://phpstan.org/r/f2efd61c-09c3-4f12-8694-a353dbb4c245

Expected output

No error should be reported.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@3aa878f

@github-actions
Copy link

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 Feb 19, 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