Skip to content

[OptionsResolver] Allow Union/Intersection Types in Resolved Closures #58917

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

Conversation

zanbaldwin
Copy link
Member

@zanbaldwin zanbaldwin commented Nov 18, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues N/A
License MIT

Using intersection/union types in Closures set in OptionsResolver currently causes the fatal error:
Attempted to call an undefined method named "getName" of class "ReflectionUnionType".
in vendor/symfony/options-resolver/OptionsResolver.php (line 235).

This can be re-created with following form type:

class ExampleType extends AbstractType
{
    public function getParent(): string
    {
        return Type\ChoiceType::class;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => MyEntity::class,
            'choice_value' => fn (\Stringable|string|null $entity): string => (string) $entity,
        ]);
    }
}

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

You can ignore the fabbot formatting issue (it's a false positive).

Thanks!

@nicolas-grekas
Copy link
Member

Thank you @zanbaldwin.

@nicolas-grekas nicolas-grekas force-pushed the bugfix/union-types-in-resolver-closures branch from 65dcf64 to 61ddfc4 Compare November 20, 2024 10:57
@nicolas-grekas nicolas-grekas merged commit cfb39c5 into symfony:6.4 Nov 20, 2024
1 check failed
@zanbaldwin zanbaldwin deleted the bugfix/union-types-in-resolver-closures branch November 20, 2024 11:47
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.

4 participants