Skip to content

Commit 000461c

Browse files
committed
Fix to testLifted
If the original type does not have the right type parameters, look in the baseclasses. Previously this was done only if the original type did not have any type parameters.
1 parent 03a2c6e commit 000461c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class TypeApplications(val self: Type) extends AnyVal {
509509
* { type $hkArg$0 = T1; ...; type $hkArg$n = Tn }
510510
*
511511
* satisfies predicate `p`. Try base types in the order of their occurrence in `baseClasses`.
512-
* A type parameter matches a varianve V if it has V as its variance or if V == 0.
512+
* A type parameter matches a variance V if it has V as its variance or if V == 0.
513513
*/
514514
def testLifted(tparams: List[Symbol], p: Type => Boolean)(implicit ctx: Context): Boolean = {
515515
def tryLift(bcs: List[ClassSymbol]): Boolean = bcs match {
@@ -534,7 +534,7 @@ class TypeApplications(val self: Type) extends AnyVal {
534534
false
535535
}
536536
if (tparams.isEmpty) false
537-
else if (typeParams.nonEmpty) p(EtaExpand)
537+
else if (typeParams.nonEmpty) p(EtaExpand) || tryLift(self.baseClasses)
538538
else tryLift(self.baseClasses)
539539
}
540540
}

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ trait TypeAssigner {
2828
}
2929
}
3030

31-
def avoid(tp: Type, syms: => List[Symbol])(implicit ctx: Context): Type = {
31+
/** An upper approximation of the given type `tp` that does not refer to any symbol in `symsToAvoid`.
32+
* Approximation steps are:
33+
*
34+
* - follow aliases if the original refers to a forbidden symbol
35+
* - widen termrefs that refer to a forbidden symbol
36+
* - replace ClassInfos of forbidden classes by the intersection of their parents, refined by all
37+
* non-private fields, methods, and type members.
38+
* - drop refinements referring to a forbidden symbol.
39+
*/
40+
def avoid(tp: Type, symsToAvoid: => List[Symbol])(implicit ctx: Context): Type = {
3241
val widenMap = new TypeMap {
33-
lazy val forbidden = syms.toSet
42+
lazy val forbidden = symsToAvoid.toSet
3443
def toAvoid(tp: Type): Boolean = tp match {
3544
case tp: TermRef =>
3645
val sym = tp.symbol

0 commit comments

Comments
 (0)