Skip to content

[PropertyInfo] Support for intersection types #42098

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
Sep 7, 2021

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jul 14, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets #41552
License MIT
Doc PR N/A

I was a bit unsure how to fix this one. PropertyInfo does not know about the concept of intersection types yet. With this PR, the component will behave exactly the same for an intersection type as for a union: You will get an array of all atomic types.

@derrabus derrabus requested a review from dunglas as a code owner July 14, 2021 13:19
@carsonbot carsonbot added this to the 4.4 milestone Jul 14, 2021
@derrabus derrabus force-pushed the bugfix/pi-intersection-types branch from 69d72d0 to 38d8741 Compare July 14, 2021 13:20
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I suppose we need a way to differentiate unions from intersections.
Putting a preemptive "changes requested" until e figure out what we need here.
(I've no idea yet :) )

@derrabus
Copy link
Member Author

@nicolas-grekas Have you made up your mind yet?

@nicolas-grekas
Copy link
Member

Nope. Maybe @dunglas has? Otherwise can you make a proposal? I'm AFK right now 😅

@derrabus
Copy link
Member Author

My proposal is this PR. Our current strategy of returning an array of types does not really work well anymore if we want to distinguish union from intersection types. I think, we can find a better representation for 5.4, but for 4.4, I just want PropertyInfo to not fall apart if we encounter an intersection.

@fabpot
Copy link
Member

fabpot commented Aug 26, 2021

This should probably be for 5.4 instead.

@derrabus
Copy link
Member Author

This should probably be for 5.4 instead.

I tend to disagree here. The component would currently throw cryptic errors if presented with an intersection type. We can certainly argue about what it should do instead, but I don't think we should leave it as is in 4.4.

@derrabus derrabus force-pushed the bugfix/pi-intersection-types branch from 38d8741 to 2bf839d Compare August 26, 2021 13:10
@ro0NL
Copy link
Contributor

ro0NL commented Aug 26, 2021

i think a list of types fits our semantic generally;

can we think of something that would conflict in practice?

ref #37971 also :) i agree about the compat issue.

@fabpot
Copy link
Member

fabpot commented Aug 26, 2021

ok, fair enough.

Signed-off-by: Alexander M. Turek <me@derrabus.de>
{
return [
['nothing', null],
['collection', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Traversable'), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Countable')]],
Copy link
Contributor

@ro0NL ro0NL Aug 26, 2021

Choose a reason for hiding this comment

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

i tend to believe the intersection type should be preserved as a single type;

[new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Traversable&Countable')]

Copy link
Member

Choose a reason for hiding this comment

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

Maybe on a higher branch, since this PR is motivated by the need to generate a proper message.
Follow up welcome.

@nicolas-grekas
Copy link
Member

Thank you @derrabus.

@nicolas-grekas nicolas-grekas merged commit 3bf2d14 into symfony:4.4 Sep 7, 2021
@derrabus derrabus deleted the bugfix/pi-intersection-types branch September 7, 2021 08:46
This was referenced Sep 28, 2021
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.

7 participants