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

Dynamic call to BackedEnum::from() not recognized #7096

Closed
derrabus opened this issue Apr 22, 2022 · 3 comments
Closed

Dynamic call to BackedEnum::from() not recognized #7096

derrabus opened this issue Apr 22, 2022 · 3 comments

Comments

@derrabus
Copy link

derrabus commented Apr 22, 2022

Bug report

When calling $someEnumClass::from($value), PHPStan does not recognize that the result is an instance of BackedEnum.

Code snippet that reproduces the problem

/**
 * @param class-string<BackedEnum> $enumClass
 */
function enumFromString(string $enumClass, string|int $value): BackedEnum
{
	return $enumClass::from($value);
}

https://phpstan.org/r/c2402ffb-9f95-4c22-b5f0-92316e622d1c

The error reported is:

Function enumFromString() should return BackedEnum but returns static.

Expected output

No errors.

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

PHPStan improves the quality of my code as well as the quality of my life as a developer.

@derrabus derrabus changed the title Dynamic call to BackedEnum::from() not recognized Dynamic call to BackedEnum::from() not recognized Apr 22, 2022
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@e97439c

@derrabus
Copy link
Author

Wow, that was fast. Thank you very much!

@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 May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants