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

Named Tuples don't propagate singleton types as widely as tuples #20267

Closed
odersky opened this issue Apr 25, 2024 · 3 comments · Fixed by #20506
Closed

Named Tuples don't propagate singleton types as widely as tuples #20267

odersky opened this issue Apr 25, 2024 · 3 comments · Fixed by #20506
Labels
Milestone

Comments

@odersky
Copy link
Contributor

odersky commented Apr 25, 2024

Compiler version

3.5-RC1, with #19174

Minimized example

import language.experimental.namedTuples

type TripleSingle = ("Lausanne", 1000, 140000)
type CitySingle = (name: "Lausanne", zip: 1000, pop: 140000)

@main def Test =
  val tripleSingle: TripleSingle = ("Lausanne", 1000, 140000) // OK
  val citySingle: CitySingle = (name = "Lausanne", zip = 1000, pop = 140000) // error

Output

-- [E007] Type Mismatch Error: named-tuple-single-ops.scala:8:31 ---------------
8 |  val citySingle: CitySingle = (name = "Lausanne", zip = 1000, pop = 140000)
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                           Found:    (name : String, zip : Int, pop : Int)
  |                           Required: CitySingle
  |
  | longer explanation available when compiling with `-explain`
1 error found

Expectation

Singleton types in an expected named tuple type should be propagated to the right-hand side just as in the case for normal tuples.

This currently fails because named tuples expand to typelevel operations that perform too much widening. It's not yet clear whether we want to pursue a solution specific to named tuples or whether we want to improve the type-level possibilities for precise types first and then build on that.

@soronpo
Copy link
Contributor

soronpo commented Apr 26, 2024

This could be a deal breaker for Named Tuples to make it to 3.5 as non-experimental. I'm not sure the compatibility story allows to just support it later.

@odersky
Copy link
Contributor Author

odersky commented Apr 26, 2024

Named tuples will be only experimental in 3.5, anyway.

@bishabosha
Copy link
Member

bishabosha commented May 31, 2024

it looks as is this was fixed by #20497 - latest nightly compiles this

@bishabosha bishabosha added the area:experimental:named-tuples Issues tied to the named tuples feature. label May 31, 2024
bishabosha added a commit to dotty-staging/dotty that referenced this issue May 31, 2024
bishabosha added a commit that referenced this issue Jun 2, 2024
As mentioned in #20267, the new desugaring from
#20497 seems to fix the issue

fixes #20267
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants