Skip to content

[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

Merged
merged 1 commit into from
Jun 30, 2025

Conversation

norkunas
Copy link
Contributor

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #...
License MIT

Tried to apply #60820 (comment) comment, but found some failing cases

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @norkunas 🙂

Copy link
Contributor Author

@norkunas norkunas left a 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 😅

@xabbuh
Copy link
Member

xabbuh commented Jun 30, 2025

Thank you @norkunas.

@xabbuh xabbuh merged commit 65eb3eb into symfony:7.3 Jun 30, 2025
8 of 11 checks passed
@norkunas norkunas deleted the fix-fromvalue branch June 30, 2025 11:31
@@ -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),
Copy link
Member

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)

Copy link
Contributor Author

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

xabbuh added a commit that referenced this pull request Jul 1, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants