Skip to content

Fix #16654 and partially fix #16583 #17592

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case tp1: MatchType =>
def compareMatch = tp2 match {
case tp2: MatchType =>
isSameType(tp1.scrutinee, tp2.scrutinee) &&
isSameType(tp1.scrutinee.widenSkolem, tp2.scrutinee.widenSkolem) &&
tp1.cases.corresponds(tp2.cases)(isSubType)
case _ => false
}
Expand Down
18 changes: 13 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ object Types {
Atoms.Range(set, set)
else Atoms.Unknown

dealias match
dealias.normalized match
case tp: SingletonType =>
tp.underlying.atoms match
case as @ Atoms.Range(lo, hi) =>
Expand Down Expand Up @@ -1456,7 +1456,7 @@ object Types {
deskolemizer(this)

/** The result of normalization using `tryNormalize`, or the type itself if
* tryNormlize yields NoType
* tryNormalize yields NoType
*/
final def normalized(using Context): Type = {
val normed = tryNormalize
Expand Down Expand Up @@ -4478,7 +4478,15 @@ object Types {
case MatchAlias(alias) =>
trace(i"normalize $this", typr, show = true) {
MatchTypeTrace.recurseWith(this) {
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
alias.applyIfParameterized(args.map(_.normalized)) match
case mt @ MatchType(bound, scrutinee, cases) =>
val scrutinee1 = scrutinee.widenSkolem
if scrutinee1 ne scrutinee then
mt.derivedMatchType(bound, scrutinee.widenSkolem, cases).normalized
else
mt.tryNormalize
case mt =>
mt.tryNormalize
}
}
case _ =>
Expand Down Expand Up @@ -4946,7 +4954,7 @@ object Types {
trace(i"reduce match type $this $hashCode", matchTypes, show = true) {
def matchCases(cmp: TrackingTypeComparer): Type =
val saved = ctx.typerState.snapshot()
try cmp.matchCases(scrutinee.normalized, cases)
try cmp.matchCases(scrutinee.normalized.widenSkolem, cases)
catch case ex: Throwable =>
handleRecursive("reduce type ", i"$scrutinee match ...", ex)
finally
Expand Down Expand Up @@ -6045,7 +6053,7 @@ object Types {
case _ =>
if args.exists(isRange) then
if variance > 0 then
tp.derivedAppliedType(tycon, args.map(rangeToBounds)) match
tp.derivedAppliedType(tycon, args.map(rangeToBounds))(using ctx.addMode(Mode.AllowLambdaWildcardApply)) match
case tp1: AppliedType if tp1.isUnreducibleWild && ctx.phase != checkCapturesPhase =>
// don't infer a type that would trigger an error later in
// Checking.checkAppliedType; fall through to default handling instead
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/16583.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import scala.compiletime.constValueTuple

val ll0: Tuple3["one", "two", "three"] = constValueTuple[("one", "two", "three")]
val ll1 = constValueTuple[("one", "two", "three")].toList
val ll3: List["one" | ("two" | ("three" | Nothing))] = constValueTuple[("one", "two", "three")].toList
val ll4: List["one" | ("two" | "three")] = constValueTuple[("one", "two", "three")].toList

inline def labels[Labels <: Tuple](using ev: Tuple.Union[Labels] <:< String): List[String] =
val tmp = constValueTuple[Labels].toList
ev.substituteCo( tmp )

def test = labels[("one", "two", "three")]

def toList(x: Tuple): List[Tuple.Union[x.type]] = ???
def test2[Labels <: Tuple] = toList((???): Labels)
7 changes: 7 additions & 0 deletions tests/pos/16654.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def toCsvFlat[A <: Product](a: A)(using m: scala.deriving.Mirror.ProductOf[A]) = {
def flatTuple(any: Any): Tuple = any match
case p: Product => p.productIterator.map(flatTuple).foldLeft(EmptyTuple: Tuple)(_ ++ _)
case a => Tuple1(a)

val tuple = flatTuple(Tuple.fromProductTyped(a)).toList
}