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

Handle & and | types when computing tuple arity #15330

Merged
merged 2 commits into from
Jun 9, 2022

Conversation

nicolasstucki
Copy link
Contributor

Fixes #15302

@nicolasstucki nicolasstucki force-pushed the fix-15302 branch 2 times, most recently from 8d036aa to a6e6c64 Compare June 2, 2022 07:44
@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Jun 2, 2022

After rebasing, I had some conflicts with #15250. The second commit (e8e30ed) fixes those conflicts, see comments on commit.

*/
def tupleArity(relaxEmptyTuple: Boolean = false)(using Context): Int = self match {
Copy link
Member

@bishabosha bishabosha Jun 9, 2022

Choose a reason for hiding this comment

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

Edit: I think this will affect the RefinedPrinter which will no longer pretty print generic tuple types

Copy link
Member

Choose a reason for hiding this comment

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

ok it seems to work for refined printer I see you made the change, disregard all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For other that may read this thread: the important thing here is that tupleElementTypes handles the EmptyTuple type alias but tupleArity does not (see comment on dealiasing)

There are cases where we know the tuple arity but cannot know the
flat element types of the tuple. For example `(A, B) | (C, D)` has
arity 2 but we cannot create a single tuple containing these elements.

In tupleArity we are missing a dealias. We need to investigate this
further. At first glance it seems that the signature of `Tuple.apply(x)`
is erased to `(Object): Product` and not `(Object): Tuple1`. This would
have been caused be the missing dealias. Unfortunately, if this is the
case we might not be able to fix the erasure without breaking binary
compatibility of the standard library.
@nicolasstucki nicolasstucki merged commit 2836fbc into scala:main Jun 9, 2022
@nicolasstucki nicolasstucki deleted the fix-15302 branch June 9, 2022 16:43
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
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.

inlined match on tuple, and expanding with *: causes class cast exception at runtime
3 participants