Skip to content

Refine bind tuple pattern typing for named tuples #23380

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
Jun 25, 2025

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Jun 16, 2025

ef getNamedTuple: (x: Int, y: String) = (x = 42, y = "Hello")

getNamedTuple match
  case t @ (a, b) => 
    // Although the pattern is a regular tuple, we are not able to call `._i` on t
    t._1 // error, _1 is not a member of named tuple

@noti0na1
Copy link
Member Author

If named tuple is a Product (#22037), then we may not need this fix. However, it is probably more difficult to make it a Product now.

@noti0na1 noti0na1 marked this pull request as ready for review June 16, 2025 12:35
@noti0na1 noti0na1 requested a review from odersky June 16, 2025 12:36
Copy link
Contributor

@natsukagami natsukagami left a comment

Choose a reason for hiding this comment

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

It's a bit strange that capturing the pattern could change the type of the scrutinee into something incompatible 😓 but it seems unavoidable, LGTM

@noti0na1 noti0na1 merged commit 4000759 into scala:main Jun 25, 2025
29 checks passed
@noti0na1 noti0na1 deleted the change-bind-tuple-pattern branch June 25, 2025 13:30
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.

3 participants