Skip to content

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

Closed
@odersky

Description

@odersky

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions