@@ -236,8 +236,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
236
236
compareWild
237
237
case tp2 : LazyRef =>
238
238
! tp2.evaluating && recur(tp1, tp2.ref)
239
- case tp2 : AnnotatedType =>
240
- recur(tp1, tp2.tpe) // todo: refine?
239
+ case tp2 : AnnotatedType if ! tp2.isRefining =>
240
+ recur(tp1, tp2.parent)
241
241
case tp2 : ThisType =>
242
242
def compareThis = {
243
243
val cls2 = tp2.cls
@@ -345,13 +345,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
345
345
// because that would cause an assertionError. Return false instead.
346
346
// See i859.scala for an example where we hit this case.
347
347
! tp1.evaluating && recur(tp1.ref, tp2)
348
- case tp1 : AnnotatedType =>
349
- recur(tp1.tpe , tp2)
348
+ case tp1 : AnnotatedType if ! tp1.isRefining =>
349
+ recur(tp1.parent , tp2)
350
350
case AndType (tp11, tp12) =>
351
351
if (tp11.stripTypeVar eq tp12.stripTypeVar) recur(tp11, tp2)
352
352
else thirdTry
353
353
case tp1 @ OrType (tp11, tp12) =>
354
- def joinOK = tp2.dealias match {
354
+ def joinOK = tp2.dealiasKeepRefiningAnnots match {
355
355
case tp2 : AppliedType if ! tp2.tycon.typeSymbol.isClass =>
356
356
// If we apply the default algorithm for `A[X] | B[Y] <: C[Z]` where `C` is a
357
357
// type parameter, we will instantiate `C` to `A` and then fail when comparing
@@ -510,7 +510,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
510
510
}
511
511
compareTypeLambda
512
512
case OrType (tp21, tp22) =>
513
- val tp1a = tp1.widenDealias
513
+ val tp1a = tp1.widenDealiasKeepRefiningAnnots
514
514
if (tp1a ne tp1)
515
515
// Follow the alias; this might avoid truncating the search space in the either below
516
516
// Note that it's safe to widen here because singleton types cannot be part of `|`.
@@ -567,6 +567,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
567
567
false
568
568
}
569
569
compareTypeBounds
570
+ case tp2 : AnnotatedType if tp2.isRefining =>
571
+ (tp1.derivesAnnotWith(tp2.annot.sameAnnotation) || defn.isBottomType(tp1)) &&
572
+ recur(tp1, tp2.parent)
570
573
case ClassInfo (pre2, cls2, _, _, _) =>
571
574
def compareClassInfo = tp1 match {
572
575
case ClassInfo (pre1, cls1, _, _, _) =>
@@ -641,7 +644,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
641
644
}
642
645
compareHKLambda
643
646
case AndType (tp11, tp12) =>
644
- val tp2a = tp2.dealias
647
+ val tp2a = tp2.dealiasKeepRefiningAnnots
645
648
if (tp2a ne tp2) // Follow the alias; this might avoid truncating the search space in the either below
646
649
return recur(tp1, tp2a)
647
650
@@ -661,6 +664,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
661
664
case _ =>
662
665
}
663
666
either(recur(tp11, tp2), recur(tp12, tp2))
667
+ case tp1 : AnnotatedType if tp1.isRefining =>
668
+ isNewSubType(tp1.parent)
664
669
case JavaArrayType (elem1) =>
665
670
def compareJavaArray = tp2 match {
666
671
case JavaArrayType (elem2) => isSubType(elem1, elem2)
@@ -685,13 +690,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
685
690
*/
686
691
def isMatchingApply (tp1 : Type ): Boolean = tp1 match {
687
692
case AppliedType (tycon1, args1) =>
688
- tycon1.dealias match {
693
+ tycon1.dealiasKeepRefiningAnnots match {
689
694
case tycon1 : TypeParamRef =>
690
695
(tycon1 == tycon2 ||
691
696
canConstrain(tycon1) && tryInstantiate(tycon1, tycon2)) &&
692
697
isSubArgs(args1, args2, tp1, tparams)
693
698
case tycon1 : TypeRef =>
694
- tycon2.dealias match {
699
+ tycon2.dealiasKeepRefiningAnnots match {
695
700
case tycon2 : TypeRef if tycon1.symbol == tycon2.symbol =>
696
701
isSubType(tycon1.prefix, tycon2.prefix) &&
697
702
isSubArgs(args1, args2, tp1, tparams)
@@ -700,7 +705,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
700
705
}
701
706
case tycon1 : TypeVar =>
702
707
isMatchingApply(tycon1.underlying)
703
- case tycon1 : AnnotatedType =>
708
+ case tycon1 : AnnotatedType if ! tycon1.isRefining =>
704
709
isMatchingApply(tycon1.underlying)
705
710
case _ =>
706
711
false
@@ -811,7 +816,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
811
816
fourthTry
812
817
}
813
818
}
814
- case _ : TypeVar | _ : AnnotatedType =>
819
+ case _ : TypeVar =>
820
+ recur(tp1, tp2.superType)
821
+ case tycon2 : AnnotatedType if ! tycon2.isRefining =>
815
822
recur(tp1, tp2.superType)
816
823
case tycon2 : AppliedType =>
817
824
fallback(tycon2.lowerBound)
@@ -1097,11 +1104,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
1097
1104
* is some combination of TypeRefs that point to classes, where the
1098
1105
* combiners are AppliedTypes, RefinedTypes, RecTypes, And/Or-Types or AnnotatedTypes.
1099
1106
*/
1100
- private def isCovered (tp : Type ): Boolean = tp.dealias .stripTypeVar match {
1107
+ private def isCovered (tp : Type ): Boolean = tp.dealiasKeepRefiningAnnots .stripTypeVar match {
1101
1108
case tp : TypeRef => tp.symbol.isClass && tp.symbol != NothingClass && tp.symbol != NullClass
1102
1109
case tp : AppliedType => isCovered(tp.tycon)
1103
1110
case tp : RefinedOrRecType => isCovered(tp.parent)
1104
- case tp : AnnotatedType => isCovered(tp.underlying)
1105
1111
case tp : AndType => isCovered(tp.tp1) && isCovered(tp.tp2)
1106
1112
case tp : OrType => isCovered(tp.tp1) && isCovered(tp.tp2)
1107
1113
case _ => false
@@ -1546,7 +1552,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
1546
1552
}
1547
1553
case tp1 : TypeVar if tp1.isInstantiated =>
1548
1554
tp1.underlying & tp2
1549
- case tp1 : AnnotatedType =>
1555
+ case tp1 : AnnotatedType if ! tp1.isRefining =>
1550
1556
tp1.underlying & tp2
1551
1557
case _ =>
1552
1558
NoType
@@ -1565,7 +1571,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
1565
1571
ExprType (rt1 | tp2.widenExpr)
1566
1572
case tp1 : TypeVar if tp1.isInstantiated =>
1567
1573
tp1.underlying | tp2
1568
- case tp1 : AnnotatedType =>
1574
+ case tp1 : AnnotatedType if ! tp1.isRefining =>
1569
1575
tp1.underlying | tp2
1570
1576
case _ =>
1571
1577
NoType
0 commit comments