Open
Description
Compiler version
Minimized code
import scala.language.experimental.namedTuples
object Test:
val f: (name: String, age: Int) = ???
val x: NamedTupleDecomposition.Names[f.type] = ("name", "age")
Output
5 | val x: NamedTupleDecomposition.Names[f.type] = ("name", "age")
| ^^^^^^^^^^^^^^^
|Found: (String, String)
|Required: NamedTupleDecomposition.Names[(Test.f : (name : String, age : Int))]
|
|Note: a match type could not be fully reduced:
|
| trying to reduce NamedTupleDecomposition.Names[(Test.f : (name : String, age : Int))]
| failed since selector (Test.f : (name : String, age : Int))
| does not match case NamedTuple.NamedTuple[n, _] => n
| and cannot be shown to be disjoint from it either.
Expectation
I'd expect this to reduce, otherwise all NamedTuple operations that use NamedTupleDecomposition
like NamedTuple.Map
will fail to reduce on singleton types. NamedTupleDecomposition is defined as:
/** Separate from NamedTuple object so that we can match on the opaque type NamedTuple. */
@experimental
object NamedTupleDecomposition:
import NamedTuple.*
/** The names of a named tuple, represented as a tuple of literal string values. */
type Names[X <: AnyNamedTuple] <: Tuple = X match
case NamedTuple[n, _] => n
So NamedTuple is treated as an abstract type constructor and we end up in
scala3/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Lines 3506 to 3511 in 7d559ad
Which fails since the scrutinee isn't widened. @sjrd : do you anticipate a soundness issue if we added a .widenSingleton
on the scrutinee here? Or is the whole design of NamedTupleDecomposition doomed?