Skip to content

[TypeInfo] Fix Type::fromValue incorrectly setting object type instead of enum#60956

Merged
xabbuh merged 1 commit intosymfony:7.3from
norkunas:fix-fromvalue
Jun 30, 2025
Merged

[TypeInfo] Fix Type::fromValue incorrectly setting object type instead of enum#60956
xabbuh merged 1 commit intosymfony:7.3from
norkunas:fix-fromvalue

Conversation

@norkunas
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

/** @var list<Type> $valueTypes */
$valueTypes = [];

$i = 0;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
}

$type = match (true) {
\is_object($value) && is_subclass_of($value::class, \UnitEnum::class) => Type::enum($value::class),
Copy link
Copy Markdown
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
Copy Markdown
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
@fabpot fabpot mentioned this pull request Jul 31, 2025
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