From 92c02ee9d514c197221fd4c4a027fe0e70e081f2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 18 Apr 2014 11:31:11 +0200 Subject: Removing duplication between Any and Object methods We cannot have same named methods defined in Object and Any because after erasure the Any references get remapped to the Object methods which would result in a double binding assertion failure. Instead we do the following: - Have some methods exist only in Any, and remap them with the Erasure denotation transformer to be owned by Object. - Have other methods exist only in Object. To achieve this, we synthesize all Any and Object methods; Objetc methods no longer get loaded from a classfile. There's a complication with getClass. We need to reconsider what the best treatment of getClass is. Right now there's too much magic going on for my taste. It might be better to leave getClass on Object only as it is in Java, forget about the special treatement of its type, and have another getClass like method in an decorator on class Any. That could produce the right types and could also work for primitive types. --- src/dotty/tools/dotc/core/transform/Erasure.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core/transform/Erasure.scala') diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala index a7981b70f..f2e3355fb 100644 --- a/src/dotty/tools/dotc/core/transform/Erasure.scala +++ b/src/dotty/tools/dotc/core/transform/Erasure.scala @@ -61,8 +61,8 @@ object Erasure { */ def transformInfo(sym: Symbol, tp: Type)(implicit ctx: Context): Type = { val erase = erasureFn(sym is JavaDefined, isSemi = true, sym.isConstructor, wildcardOK = false) - if ((sym eq defn.Object_asInstanceOf) || - (sym eq defn.Object_isInstanceOf) || + if ((sym eq defn.Any_asInstanceOf) || + (sym eq defn.Any_isInstanceOf) || (sym.owner eq defn.ArrayClass) && (sym.isType || sym.isConstructor)) sym.info else if (sym.isAbstractType) TypeAlias(WildcardType) else erase(tp) -- cgit v1.2.3