@@ -5,6 +5,7 @@ package tpe
55import scala .collection .{ mutable }
66import Flags ._
77import util .Statistics
8+ import scala .annotation .tailrec
89
910trait TypeComparers {
1011 self : SymbolTable =>
@@ -583,9 +584,9 @@ trait TypeComparers {
583584
584585
585586 def isWeakSubType (tp1 : Type , tp2 : Type ) =
586- tp1.deconst.normalize match {
587+ tp1.dealiasWiden match {
587588 case TypeRef (_, sym1, _) if isNumericValueClass(sym1) =>
588- tp2.deconst.normalize match {
589+ tp2.deconst.dealias match {
589590 case TypeRef (_, sym2, _) if isNumericValueClass(sym2) =>
590591 isNumericSubClass(sym1, sym2)
591592 case tv2 @ TypeVar (_, _) =>
@@ -594,7 +595,7 @@ trait TypeComparers {
594595 isSubType(tp1, tp2)
595596 }
596597 case tv1 @ TypeVar (_, _) =>
597- tp2.deconst.normalize match {
598+ tp2.deconst.dealias match {
598599 case TypeRef (_, sym2, _) if isNumericValueClass(sym2) =>
599600 tv1.registerBound(tp2, isLowerBound = false , isNumericBound = true )
600601 case _ =>
@@ -604,14 +605,18 @@ trait TypeComparers {
604605 isSubType(tp1, tp2)
605606 }
606607
607- /** The isNumericValueType tests appear redundant, but without them
608- * test/continuations-neg/function3.scala goes into an infinite loop.
609- * (Even if the calls are to typeSymbolDirect.)
610- */
611- def isNumericSubType (tp1 : Type , tp2 : Type ): Boolean = (
612- isNumericValueType(tp1)
613- && isNumericValueType(tp2)
614- && isNumericSubClass(tp1.typeSymbol, tp2.typeSymbol)
615- )
616-
608+ def isNumericSubType (tp1 : Type , tp2 : Type ) = (
609+ isNumericSubClass(primitiveBaseClass(tp1.dealiasWiden), primitiveBaseClass(tp2.dealias))
610+ )
611+
612+ /** If the given type has a primitive class among its base classes,
613+ * the symbol of that class. Otherwise, NoSymbol.
614+ */
615+ private def primitiveBaseClass (tp : Type ): Symbol = {
616+ @ tailrec def loop (bases : List [Symbol ]): Symbol = bases match {
617+ case Nil => NoSymbol
618+ case x :: xs => if (isPrimitiveValueClass(x)) x else loop(xs)
619+ }
620+ loop(tp.baseClasses)
621+ }
617622}
0 commit comments