aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/TypeErasure.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-30 13:02:56 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-30 13:02:56 +0200
commit4041c5d590f78323d640c6eec7e370a37a01c416 (patch)
tree15e33ffb26e1bfd4c47842670dee696c582322bf /src/dotty/tools/dotc/TypeErasure.scala
parent5362969b55cc73c22ea959d1960e3696a801c469 (diff)
downloaddotty-4041c5d590f78323d640c6eec7e370a37a01c416.tar.gz
dotty-4041c5d590f78323d640c6eec7e370a37a01c416.tar.bz2
dotty-4041c5d590f78323d640c6eec7e370a37a01c416.zip
Ensure that after erasure all types are erased.
Defines a predicate isErasedTypes and checks that all tree types and their widened underlying types are erased.
Diffstat (limited to 'src/dotty/tools/dotc/TypeErasure.scala')
-rw-r--r--src/dotty/tools/dotc/TypeErasure.scala38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/TypeErasure.scala b/src/dotty/tools/dotc/TypeErasure.scala
index 63b4f396b..d2b241e71 100644
--- a/src/dotty/tools/dotc/TypeErasure.scala
+++ b/src/dotty/tools/dotc/TypeErasure.scala
@@ -1,17 +1,18 @@
package dotty.tools.dotc
package core
-import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Flags.JavaDefined
+import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Decorators._, Flags.JavaDefined
import util.DotClass
/** Erased types are:
*
- * TypeRef(NoPrefix, denot is ClassDenotation)
- * TermRef(NoPrefix, denot is SymDenotation)
+ * TypeRef(prefix is ignored, denot is ClassDenotation)
+ * TermRef(prefix is ignored, denot is SymDenotation)
* JavaArrayType
* AnnotatedType
- * MethodType ----+-- JavaMethodType
- * ClassInfo
+ * MethodType
+ * ThisType
+ * ClassInfo (NoPrefix, ...)
* NoType
* NoPrefix
* WildcardType
@@ -22,6 +23,30 @@ import util.DotClass
*/
object TypeErasure {
+ /** A predicate that tests whether a type is a legal erased type. Only asInstanceOf and
+ * isInstanceOf may have types that do not satisfy the predicate.
+ */
+ def isErasedType(tp: Type)(implicit ctx: Context): Boolean = tp match {
+ case tp: TypeRef =>
+ tp.symbol.isClass
+ case _: TermRef =>
+ true
+ case JavaArrayType(elem) =>
+ isErasedType(elem)
+ case AnnotatedType(_, tp) =>
+ isErasedType(tp)
+ case ThisType(tref) =>
+ isErasedType(tref)
+ case tp: MethodType =>
+ tp.paramTypes.forall(isErasedType) && isErasedType(tp.resultType)
+ case tp @ ClassInfo(pre, _, parents, decls, _) =>
+ isErasedType(pre) && parents.forall(isErasedType) //&& decls.forall(sym => isErasedType(sym.info)) && isErasedType(tp.selfType)
+ case NoType | NoPrefix | WildcardType | ErrorType =>
+ true
+ case _ =>
+ false
+ }
+
case class ErasedValueType(cls: ClassSymbol, underlying: Type) extends CachedGroundType {
override def computeHash = doHash(cls, underlying)
}
@@ -179,6 +204,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
* - For a typeref P.C where C refers to a class, <noprefix> # C.
* - For a typeref P.C where C refers to an alias type, the erasure of C's alias.
* - For a typeref P.C where C refers to an abstract type, the erasure of C's upper bound.
+ * - For a this-type C.this, the type itself.
* - For all other type proxies: The erasure of the underlying type.
* - For T1 & T2, the erased glb of |T1| and |T2| (see erasedGlb)
* - For T1 | T2, the first base class in the linearization of T which is also a base class of T2
@@ -208,6 +234,8 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
case tp: TermRef =>
assert(tp.symbol.exists, tp)
TermRef(NoPrefix, tp.symbol.asTerm)
+ case ThisType(_) =>
+ tp
case ExprType(rt) =>
MethodType(Nil, Nil, this(rt))
case tp: TypeProxy =>