File tree 2 files changed +23
-6
lines changed
compiler/src/dotty/tools/dotc 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -440,24 +440,29 @@ object Types {
440
440
NoSymbol
441
441
}
442
442
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
444
444
*/
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 {
446
446
case tp : ClassInfo =>
447
447
tp.cls :: Nil
448
448
case tp : TypeRef =>
449
449
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)
451
451
case tp : TypeProxy =>
452
- tp.underlying.classSymbols
452
+ tp.underlying.parentSymbols(include)
453
453
case AndType (l, r) =>
454
- l.classSymbols | r.classSymbols
454
+ l.parentSymbols(include) | r.parentSymbols(include)
455
455
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
457
457
case _ =>
458
458
Nil
459
459
}
460
460
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
+
461
466
/** The term symbol associated with the type */
462
467
@ tailrec final def termSymbol (implicit ctx : Context ): Symbol = this match {
463
468
case tp : TermRef => tp.symbol
Original file line number Diff line number Diff line change @@ -492,7 +492,19 @@ trait ImplicitRunInfo { self: Run =>
492
492
object liftToClasses extends TypeMap {
493
493
override implicit protected val ctx : Context = liftingCtx
494
494
override def stopAtStatic = true
495
+
495
496
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
+ }
496
508
case tp : NamedType =>
497
509
tp.info match {
498
510
case TypeAlias (alias) =>
You can’t perform that action at this time.
0 commit comments