-
Couldn't load subscription status.
- Fork 1.1k
Open
Labels
area:match-typesarea:named-tuplesIssues tied to the named tuples feature.Issues tied to the named tuples feature.itype:bug
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, _] => nSo 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
| case MatchTypeCasePattern.AbstractTypeConstructor(tycon, argPatterns) => | |
| scrut.dealias match | |
| case scrutDealias @ AppliedType(scrutTycon, args) if scrutTycon =:= tycon => | |
| matchArgs(argPatterns, args, tycon.typeParams, scrutIsWidenedAbstract) | |
| case _ => | |
| false |
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?
Metadata
Metadata
Assignees
Labels
area:match-typesarea:named-tuplesIssues tied to the named tuples feature.Issues tied to the named tuples feature.itype:bug