Skip to content

Commit 7a1c1c9

Browse files
authored
Merge pull request #11435 from dotty-staging/fix-11393
More robust comparison of type constructors in provablyDisjoint
2 parents 79ba06c + 212ff60 commit 7a1c1c9

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object Printers {
3131
val init = noPrinter
3232
val inlining = noPrinter
3333
val interactiv = noPrinter
34+
val matchTypes = noPrinter
3435
val nullables = noPrinter
3536
val overload = noPrinter
3637
val patmatch = noPrinter

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import collection.mutable
1111
import util.Stats
1212
import config.Config
1313
import config.Feature.migrateTo3
14-
import config.Printers.{constr, subtyping, gadts, noPrinter}
14+
import config.Printers.{constr, subtyping, gadts, matchTypes, noPrinter}
1515
import TypeErasure.{erasedLub, erasedGlb}
1616
import TypeApplications._
1717
import Variances.{Variance, variancesConform}
@@ -2406,7 +2406,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24062406
* property that in all possible contexts, the same match type expression
24072407
* is either stuck or reduces to the same case.
24082408
*/
2409-
def provablyDisjoint(tp1: Type, tp2: Type)(using Context): Boolean = {
2409+
def provablyDisjoint(tp1: Type, tp2: Type)(using Context): Boolean = trace(i"provable disjoint $tp1, $tp2", matchTypes) {
24102410
// println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")
24112411

24122412
def isEnumValueOrModule(ref: TermRef): Boolean =
@@ -2450,7 +2450,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24502450
decompose(cls2, tp2).forall(x => provablyDisjoint(x, tp1))
24512451
else
24522452
false
2453-
case (AppliedType(tycon1, args1), AppliedType(tycon2, args2)) if tycon1 == tycon2 =>
2453+
case (AppliedType(tycon1, args1), AppliedType(tycon2, args2))
2454+
if tycon1.typeSymbol == tycon2.typeSymbol && tycon1 =:= tycon2 =>
24542455
// It is possible to conclude that two types applies are disjoint by
24552456
// looking at covariant type parameters if the said type parameters
24562457
// are disjoin and correspond to fields.
@@ -2766,7 +2767,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
27662767
* None if the match fails and we should consider the following cases
27672768
* because scrutinee and pattern do not overlap
27682769
*/
2769-
def matchCase(cas: Type): Option[Type] = {
2770+
def matchCase(cas: Type): Option[Type] = trace(i"match case $cas vs $scrut", matchTypes) {
27702771
val cas1 = cas match {
27712772
case cas: HKTypeLambda =>
27722773
caseLambda = constrained(cas)

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import config.Config
3333
import annotation.{tailrec, constructorOnly}
3434
import language.implicitConversions
3535
import scala.util.hashing.{ MurmurHash3 => hashing }
36-
import config.Printers.{core, typr}
36+
import config.Printers.{core, typr, matchTypes}
3737
import reporting.{trace, Message}
3838
import java.lang.ref.WeakReference
3939

@@ -4495,7 +4495,7 @@ object Types {
44954495
record("MatchType.reduce computed")
44964496
if (myReduced != null) record("MatchType.reduce cache miss")
44974497
myReduced =
4498-
trace(i"reduce match type $this $hashCode", typr, show = true) {
4498+
trace(i"reduce match type $this $hashCode", matchTypes, show = true) {
44994499
def matchCases(cmp: TrackingTypeComparer): Type =
45004500
try cmp.matchCases(scrutinee.normalized, cases)
45014501
catch case ex: Throwable =>

tests/pos/i11393/Format_1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Formatt:
2+
type ToFormat[X <: Tuple] = X match
3+
case EmptyTuple => String
4+
case '%' *: 's' *: ts => (String => ToFormat[ts])
5+
case Char *: ts => ToFormat[ts]
6+
7+

tests/pos/i11393/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@main def hello: Unit = {
2+
val x: Formatt.ToFormat['a' *: EmptyTuple] = ""
3+
4+
5+
}

0 commit comments

Comments
 (0)