Skip to content

Commit db2390b

Browse files
committed
Revise liftToClasses to make CB work
The difference is that in an alias type `p.A = q.B` we take `p` instead of `q` as the prefix to search.
1 parent ff844b5 commit db2390b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,24 +440,29 @@ object Types {
440440
NoSymbol
441441
}
442442

443-
/** The least (wrt <:<) set of class symbols of which this type is a subtype
443+
/** The least (wrt <:<) set of symbols satisfying the `include` prediacte of which this type is a subtype
444444
*/
445-
final def classSymbols(implicit ctx: Context): List[ClassSymbol] = this match {
445+
final def parentSymbols(include: Symbol => Boolean)(implicit ctx: Context): List[Symbol] = this match {
446446
case tp: ClassInfo =>
447447
tp.cls :: Nil
448448
case tp: TypeRef =>
449449
val sym = tp.symbol
450-
if (sym.isClass) sym.asClass :: Nil else tp.superType.classSymbols
450+
if (include(sym)) sym :: Nil else tp.superType.parentSymbols(include)
451451
case tp: TypeProxy =>
452-
tp.underlying.classSymbols
452+
tp.underlying.parentSymbols(include)
453453
case AndType(l, r) =>
454-
l.classSymbols | r.classSymbols
454+
l.parentSymbols(include) | r.parentSymbols(include)
455455
case OrType(l, r) =>
456-
l.classSymbols intersect r.classSymbols // TODO does not conform to spec
456+
l.parentSymbols(include) intersect r.parentSymbols(include) // TODO does not conform to spec
457457
case _ =>
458458
Nil
459459
}
460460

461+
/** The least (wrt <:<) set of class symbols of which this type is a subtype
462+
*/
463+
final def classSymbols(implicit ctx: Context): List[ClassSymbol] =
464+
parentSymbols(_.isClass).asInstanceOf
465+
461466
/** The term symbol associated with the type */
462467
@tailrec final def termSymbol(implicit ctx: Context): Symbol = this match {
463468
case tp: TermRef => tp.symbol

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,19 @@ trait ImplicitRunInfo { self: Run =>
492492
object liftToClasses extends TypeMap {
493493
override implicit protected val ctx: Context = liftingCtx
494494
override def stopAtStatic = true
495+
495496
def apply(tp: Type) = tp match {
497+
case tp: TypeRef =>
498+
val sym = tp.symbol
499+
if (sym.isClass || sym.isOpaqueAlias) tp
500+
else {
501+
val pre = tp.prefix
502+
def joinClass(tp: Type, cls: Symbol) =
503+
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner))
504+
val lead = if (pre eq NoPrefix) defn.AnyType else apply(pre)
505+
def isLiftTarget(sym: Symbol) = sym.isClass || sym.isOpaqueAlias
506+
(lead /: tp.parentSymbols(isLiftTarget))(joinClass)
507+
}
496508
case tp: NamedType =>
497509
tp.info match {
498510
case TypeAlias(alias) =>

0 commit comments

Comments
 (0)