Skip to content

Commit ec3019e

Browse files
committed
Make widening ops more systematic & complete
1) strip TypeVars wehere necessary before widening 2) allow the combination of widening and dealiasing, in any order.
1 parent 2216759 commit ec3019e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ object Types {
272272
if (lsym isSubClass rsym) lsym
273273
else if (rsym isSubClass lsym) rsym
274274
else NoSymbol
275-
case OrType(l, r) =>
275+
case OrType(l, r) => // TODO does not conform to spec
276276
val lsym = l.classSymbol
277277
val rsym = r.classSymbol
278278
if (lsym isSubClass rsym) rsym
@@ -295,7 +295,7 @@ object Types {
295295
case AndType(l, r) =>
296296
l.classSymbols union r.classSymbols
297297
case OrType(l, r) =>
298-
l.classSymbols intersect r.classSymbols
298+
l.classSymbols intersect r.classSymbols // TODO does not conform to spec
299299
case _ =>
300300
Nil
301301
}
@@ -563,7 +563,7 @@ object Types {
563563
*/
564564
final def baseTypeRef(base: Symbol)(implicit ctx: Context): Type = /*ctx.traceIndented(s"$this baseTypeRef $base")*/ /*>|>*/ track("baseTypeRef") /*<|<*/ {
565565
base.denot match {
566-
case classd: ClassDenotation => classd.baseTypeRefOf(this) //widen.dealias)
566+
case classd: ClassDenotation => classd.baseTypeRefOf(this)
567567
case _ => NoType
568568
}
569569
}
@@ -598,22 +598,23 @@ object Types {
598598
}
599599

600600
/** Widen from singleton type to its underlying non-singleton
601-
* base type by applying one or more `underlying` dereferences,
601+
* base type by applying one or more `underlying` dereferences.
602602
*/
603-
final def widenSingleton(implicit ctx: Context): Type = this match {
603+
final def widenSingleton(implicit ctx: Context): Type = stripTypeVar match {
604604
case tp: SingletonType if !tp.isOverloaded => tp.underlying.widenSingleton
605605
case _ => this
606606
}
607607

608608
/** Widen from ExprType type to its result type.
609+
* (Note: no stripTypeVar needed because TypeVar's can't refer to ExprTypes.)
609610
*/
610611
final def widenExpr: Type = this match {
611612
case tp: ExprType => tp.resultType
612613
case _ => this
613614
}
614615

615616
/** Widen type if it is unstable (i.e. an EpxprType, or Termref to unstable symbol */
616-
final def widenIfUnstable(implicit ctx: Context): Type = this match {
617+
final def widenIfUnstable(implicit ctx: Context): Type = stripTypeVar match {
617618
case tp: ExprType => tp.resultType.widenIfUnstable
618619
case tp: TermRef if !tp.symbol.isStable => tp.underlying.widenIfUnstable
619620
case _ => this
@@ -636,10 +637,16 @@ object Types {
636637
case tp => tp
637638
}
638639

640+
/** Peform successive widenings and dealiasings until none can be applied anymore */
641+
final def widenDealias(implicit ctx: Context): Type = {
642+
val res = this.widen.dealias
643+
if (res eq this) res else res.widenDealias
644+
}
645+
639646
/** Widen from constant type to its underlying non-constant
640647
* base type.
641648
*/
642-
final def deconst(implicit ctx: Context): Type = this match {
649+
final def deconst(implicit ctx: Context): Type = stripTypeVar match {
643650
case tp: ConstantType => tp.value.tpe
644651
case _ => this
645652
}

0 commit comments

Comments
 (0)