diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/Types.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 9345d9d26e..ef45834ab7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -1220,7 +1220,7 @@ trait Types extends reflect.generic.Types { self: SymbolTable => override def bounds: TypeBounds = this def containsType(that: Type) = that match { case TypeBounds(_, _) => that <:< this - case _ => lo <:< that && that <:< hi + case _ => lo <:< that && that <:< hi } // override def isNullable: Boolean = NullClass.tpe <:< lo; override def safeToString = ">: " + lo + " <: " + hi @@ -1228,6 +1228,10 @@ trait Types extends reflect.generic.Types { self: SymbolTable => } object TypeBounds extends TypeBoundsExtractor { + def empty: TypeBounds = apply(NothingClass.tpe, AnyClass.tpe) + def upper(hi: Type): TypeBounds = apply(NothingClass.tpe, hi) + def lower(lo: Type): TypeBounds = apply(lo, AnyClass.tpe) + def apply(lo: Type, hi: Type): TypeBounds = unique(new TypeBounds(lo, hi) with UniqueType) } @@ -2848,13 +2852,13 @@ A type's typeSymbol should never be inspected directly. // Hash consing -------------------------------------------------------------- private val initialUniquesCapacity = 4096 - private var uniques: util.HashSet[AnyRef] = _ + private var uniques: util.HashSet[Type] = _ private var uniqueRunId = NoRunId - private def unique[T <: AnyRef](tp: T): T = { + private def unique[T <: Type](tp: T): T = { incCounter(rawTypeCount) if (uniqueRunId != currentRunId) { - uniques = new util.HashSet("uniques", initialUniquesCapacity) + uniques = util.HashSet[Type]("uniques", initialUniquesCapacity) uniqueRunId = currentRunId } (uniques findEntryOrUpdate tp).asInstanceOf[T] @@ -2862,6 +2866,12 @@ A type's typeSymbol should never be inspected directly. // Helper Classes --------------------------------------------------------- + /** @PP: Unable to see why these apparently constant types should need vals + * in every TypeConstraint, I lifted them out. + */ + private lazy val numericLoBound = IntClass.tpe + private lazy val numericHiBound = intersectionType(List(ByteClass.tpe, CharClass.tpe), ScalaPackageClass) + /** A class expressing upper and lower bounds constraints of type variables, * as well as their instantiations. */ @@ -2877,13 +2887,6 @@ A type's typeSymbol should never be inspected directly. def loBounds: List[Type] = if (numlo == NoType) lobounds else numlo :: lobounds def hiBounds: List[Type] = if (numhi == NoType) hibounds else numhi :: hibounds - /** @PP: Would it be possible to get a comment explaining what role these are serving? - * In particular, why is numericHiBound being calculated this way given that all the - * arguments are constant? - */ - private val numericLoBound = IntClass.tpe - private val numericHiBound = intersectionType(List(ByteClass.tpe, CharClass.tpe), ScalaPackageClass) - def addLoBound(tp: Type, isNumericBound: Boolean = false) { if (isNumericBound && isNumericValueType(tp)) { if (numlo == NoType || isNumericSubType(numlo, tp)) @@ -3233,7 +3236,7 @@ A type's typeSymbol should never be inspected directly. } def singletonBounds(hi: Type) = { - TypeBounds(NothingClass.tpe, intersectionType(List(hi, SingletonClass.tpe))) + TypeBounds.upper(intersectionType(List(hi, SingletonClass.tpe))) } /** A map to compute the asSeenFrom method */ @@ -5243,7 +5246,7 @@ A type's typeSymbol should never be inspected directly. val symbounds = symtypes filter isTypeBound var result: Type = if (symbounds.isEmpty) - TypeBounds(NothingClass.tpe, AnyClass.tpe) + TypeBounds.empty else glbBounds(symbounds) for (t <- symtypes if !isTypeBound(t)) if (result.bounds containsType t) result = t |