-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TypeInfo] Fix Type::fromValue
incorrectly setting object type instead of enum
#60956
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @norkunas 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh sure, but I think better would be to wrap whole match with is_object
@@ -428,8 +429,6 @@ public static function fromValue(mixed $value): Type | |||
/** @var list<Type> $valueTypes */ | |||
$valueTypes = []; | |||
|
|||
$i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops 😅
Thank you @norkunas. |
@@ -412,6 +412,7 @@ public static function fromValue(mixed $value): Type | |||
} | |||
|
|||
$type = match (true) { | |||
\is_object($value) && is_subclass_of($value::class, \UnitEnum::class) => Type::enum($value::class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$value instanceof \UnitEnum
would be better (instanceof
has more built-in optimizations than is_subclass_of()
btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will change it. I just copied it from TypeFactoryTrait::enum
method
This PR was merged into the 7.3 branch. Discussion ---------- [TypeInfo] Optimize enum check | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #60956 (comment) | License | MIT Commits ------- e8b8282 [TypeInfo] Optimize enum check
Tried to apply #60820 (comment) comment, but found some failing cases