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

Fix BackedEnum::tryFrom not being nullable #2302

Closed

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented Mar 24, 2023

I encountered this case: https://phpstan.org/r/c1013cf7-d2ea-4d7a-91a9-9839456e5740 where the result of tryFrom is incorrectly being reported as not nullable when converting a superset enum to a subset enum. Here is my attempt to fix it.

In addition, the original extension ignores the possibility of strict_types not being enabled. I kept this behavior, as I'm not sure what the policy is with regards to strict_types (i.e. it seems that isDeclareStrictTypes is not called from any other type extension). But I at least added a few tests for strict_types=1.

@schlndh schlndh force-pushed the fix-BackedEnumTryFromNotNullable branch from af6a631 to 207d252 Compare March 24, 2023 12:41
schlndh added a commit to schlndh/maria-stan that referenced this pull request Mar 25, 2023
@schlndh schlndh force-pushed the fix-BackedEnumTryFromNotNullable branch from 207d252 to 8b1b035 Compare April 14, 2023 09:47
@schlndh schlndh changed the base branch from 1.10.x to 1.11.x April 14, 2023 09:48
@ondrejmirtes
Copy link
Member

ondrejmirtes commented Apr 14, 2023

Hi, I'm sorry, but I don't understand your change in BackedEnumFromMethodDynamicReturnTypeExtension. But I fixed it myself while keeping you as the author (plus I used your tests): bb31aab?w=1

@schlndh schlndh deleted the fix-BackedEnumTryFromNotNullable branch April 14, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants