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

Adapt generic tuples to be able to access members #14242

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jan 10, 2022

Fixes #14215

With this change, the _N members of TupleN can be selected on generic tuples of known arity. This also includes the Tuple2.swap method.

@nicolasstucki
Copy link
Contributor Author

This still does not fix the issues when inlining (#14209), but it seems to go in the right direction to fix that issue as well.

@nicolasstucki nicolasstucki marked this pull request as ready for review January 11, 2022 15:00
@nicolasstucki nicolasstucki removed their assignment Jan 11, 2022
@nicolasstucki nicolasstucki merged commit 9e14f5f into scala:master Jan 18, 2022
@nicolasstucki nicolasstucki deleted the fix-tuple-member-selection branch January 18, 2022 10:29
@SethTisue
Copy link
Member

SethTisue commented Sep 15, 2022

Curious whether the restriction to known arity was just a matter of ambition-level-at-present, or whether a design decision has been made that x._1 here not only doesn't, but actually shouldn't work:

scala> def foo[T <: Tuple](x: Int *: T) = x(0)
def foo[T <: Tuple](x: Int *: T): Int
                                                                                                    
scala> def foo[T <: Tuple](x: Int *: T) = x._1
-- [E008] Not Found Error: -----------------------------------------------------
1 |def foo[T <: Tuple](x: Int *: T) = x._1
  |                                   ^^^^
  |                  value _1 is not a member of Int *: T
  |
  |                  where:    T is a type in method foo with bounds <: Tuple
1 error found

In a classroom, I'd have trouble explaining to a student why (0) and ._1 aren't exactly the same, in every context.

@odersky
Copy link
Contributor

odersky commented Sep 15, 2022

I think the answer is that we should deprecate the selectors and only use indexing.

@SethTisue
Copy link
Member

SethTisue commented Sep 15, 2022

I think the answer is that we should deprecate the selectors and only use indexing.

Hmm, interesting.

Dale points out that tuples are products and that product elements must have names. But I guess any further unpacking of the implications of your suggestion should move to a new ticket.

related: #15253

@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 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.

Inconsistency with member selection of generic tuples with know TupleN
5 participants