Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix generic type for FormErrorIterator #45322

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

akalineskou
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

After upgrading symfony/form (v5.4.2 => v5.4.3) I was getting weird phpstan errors

Instanceof between Symfony\Component\Form\FormError and Symfony\Component\Form\FormErrorIterator will always evaluate to false.

I pass FormErrorIterator $formErrors and iterate over it, and do different things if it's an instance of FormErrorIterator or FormError
This change fixes it

It was introduced here
https://github.com/symfony/symfony/pull/42471/files#diff-48af5e26fa9979e5508cc18c8921ed13fd1a870706108285bada83f18278ff8eR32

@carsonbot carsonbot added this to the 5.4 milestone Feb 4, 2022
@akalineskou akalineskou changed the title Fix generic type for FormErrorIterator [Form] Fix generic type for FormErrorIterator Feb 4, 2022
@carsonbot carsonbot changed the title [Form] Fix generic type for FormErrorIterator Fix generic type for FormErrorIterator Feb 5, 2022
@fabpot
Copy link
Member

fabpot commented Feb 5, 2022

Thank you @akalineskou.

@fabpot fabpot merged commit 2e32f2f into symfony:5.4 Feb 5, 2022
@akalineskou akalineskou deleted the form-fix-generic-type-for-form-error-iterator branch February 5, 2022 12:44
This was referenced Feb 28, 2022
fabpot added a commit that referenced this pull request Mar 12, 2022
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

Make FormErrorIterator generic

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes/no
| New feature?  | yes/no
| Deprecations? | no
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

I target 5.4, since it's a follow up of #45322 which introduced some errors in my code.

It allows to typehint the `Form::getErrors` method to return `FormErrorIterator<FormError>` most of the time (which is possible by psalm/phpstan plugins with ReturnTypeProviders).

Commits
-------

08ddac5 Make FormErrorIterator generic
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.