Skip to content
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

fix: Fix parsing of invalid intersection types #8385

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

danog
Copy link
Collaborator

@danog danog commented Aug 9, 2022

This fixes #8333 properly, replacing #8384.
I feel that we need to be consistent with the return type of Type::intersectUnionTypes: if there is no possible intersection between the types, return null, otherwise return a Union with the types.
The previous PR incorrectly returned TNever only for certain invalid intersections: if we really want to go with that approach, then let's always return either a Union or a Union(TNever), and never null (but I would personally leave it as it is right now, as it's easier to tell if there's no intersection between the types this way).

petewalker and others added 11 commits August 8, 2022 23:54
Returns `TNever` for an intersection of 2 non-overlapping named classes instead of throwing an exception. Will raise a new `InvalidIntersectionType` in the case that this is detected.

Psalm will now also raise a parse error instead of throwing if it cannot deduce the resolved intersection type.

Resolves vimeo#8333
@danog danog changed the title Fix parsing of invalid intersection types fix: Fix parsing of invalid intersection types Aug 9, 2022
@orklah
Copy link
Collaborator

orklah commented Aug 10, 2022

Well, the question is, does Type::intersectUnionTypes sometimes return a Never anyway?

If it can happen, it would definitely mean a InvalidIntersectionType should be emitted and your change would not do that. If it can't happen then yeah, we should try to keep consistency.

@danog
Copy link
Collaborator Author

danog commented Aug 11, 2022

All fixed!

@danog
Copy link
Collaborator Author

danog commented Aug 11, 2022

Actually nevermind, it seems like there's a bug in the InArray assertion reconciler

@weirdan
Copy link
Collaborator

weirdan commented Dec 3, 2022

Actually nevermind, it seems like there's a bug in the InArray assertion reconcile

@danog Isn't it something you were fixing in #8773 (among other things)?

Comment on lines +546 to +547
Union $type_1,
Union $type_2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need this BC break here? This is a part of our API surface, so the earliest it can change is in Psalm 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Psalm crashing with intersection types in latest builds
4 participants