aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-04-10 15:19:13 +0200
committerMartin Odersky <odersky@gmail.com>2013-04-10 15:19:13 +0200
commit87ae863c3efa7ce41fed81b783855c572d541898 (patch)
tree590151812be9d41257e7c4b5d5f804853be78d31 /src/dotty/tools/dotc/core/Types.scala
parent1034d4e420c2b0724945486f341c53a07e6a90e0 (diff)
downloaddotty-87ae863c3efa7ce41fed81b783855c572d541898.tar.gz
dotty-87ae863c3efa7ce41fed81b783855c572d541898.tar.bz2
dotty-87ae863c3efa7ce41fed81b783855c572d541898.zip
Re-organized comparisons of types with classes.
New methods: isClassType, derivesFrom, isArray. Refactored calls to typeSymbol and <:< into these. Made sure to use dealias where needed on remaining typeSymbol calls.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 7656835cf..133018a96 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -90,7 +90,18 @@ object Types {
case _ => false
}
- /** A type T is a legal prefix in a type selection T#A if
+ /** Is this type an instance of the given class `cls`? */
+ final def isClassType(cls: Symbol)(implicit ctx: Context): Boolean =
+ dealias.typeSymbol == cls
+
+ /** Is this type an instance of a non-bottom subclass of the given class `cls`? */
+ final def derivesFrom(cls: Symbol)(implicit ctx: Context): Boolean =
+ classSymbol.derivesFrom(cls)
+
+ /** Is this an array type? */
+ final def isArray(implicit ctx: Context): Boolean = isClassType(defn.ArrayClass)
+
+ /** A type T is a legal prefix in a type selection T#A if
* T is stable or T contains no uninstantiated type variables.
*/
final def isLegalPrefix(implicit ctx: Context): Boolean =
@@ -101,7 +112,7 @@ object Types {
* be refined later.
*/
final def isNotNull(implicit ctx: Context): Boolean =
- widen.typeSymbol is ModuleClass
+ classSymbol is ModuleClass
/** Is this type produced as a repair for an error? */
final def isError(implicit ctx: Context): Boolean =
@@ -448,7 +459,7 @@ object Types {
/** Map references to Object to references to Any; needed for Java interop */
final def objToAny(implicit ctx: Context) =
- if (typeSymbol == defn.ObjectClass && !ctx.phase.erasedTypes) defn.AnyType else this
+ if (isClassType(defn.ObjectClass) && !ctx.phase.erasedTypes) defn.AnyType else this
// ----- Access to parts --------------------------------------------
@@ -684,8 +695,8 @@ object Types {
final def argType(tparam: Symbol)(implicit ctx: Context): Type = this match {
case TypeBounds(lo, hi) =>
val v = tparam.variance
- if (v > 0 && lo.typeSymbol == defn.NothingClass) hi
- else if (v < 0 && hi.typeSymbol == defn.AnyClass) lo
+ if (v > 0 && lo.isClassType(defn.NothingClass)) hi
+ else if (v < 0 && hi.isClassType(defn.AnyClass)) lo
else if (v == 0 && (lo eq hi)) lo
else NoType
case _ =>
@@ -698,7 +709,7 @@ object Types {
*/
final def splitArray(implicit ctx: Context): (Int, Type) = {
def recur(n: Int, tp: Type): (Int, Type) = tp match {
- case RefinedType(tycon, _) if tycon.dealias.typeSymbol == defn.ArrayClass =>
+ case RefinedType(tycon, _) if tycon.isArray =>
tp.typeArgs match {
case arg :: Nil => recur(n + 1, arg)
case _ => (n, tp)