From 70e57128bb7623998f76aaf2ad8541d438b4b2b8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 22 Dec 2013 16:19:09 +0100 Subject: Normalize parents to be class refs Previously, alias type refs were also accepted. But this is the wrong assumption for computeMembersNames. So, e.g. instead of leaving an AnyRef we now expand to Object. Also making ==, != take an Any instead of Object --- src/dotty/tools/dotc/core/Definitions.scala | 6 +++--- src/dotty/tools/dotc/core/TypeOps.scala | 7 ++++--- src/dotty/tools/dotc/core/pickling/UnPickler.scala | 2 +- src/dotty/tools/dotc/typer/Namer.scala | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index 96e4f0138..a2527c9f2 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -45,7 +45,7 @@ class Definitions(implicit ctx: Context) { if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.typeRef) else tpe val parents = parentConstrs.toList map instantiate - val parentRefs: List[TypeRef] = ctx.normalizeToRefs(parents, cls, paramDecls) + val parentRefs: List[TypeRef] = ctx.normalizeToClassRefs(parents, cls, paramDecls) denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parentRefs, paramDecls) } } @@ -98,8 +98,8 @@ class Definitions(implicit ctx: Context) { lazy val AnyRefAlias: TypeSymbol = newAliasType(tpnme.AnyRef, ObjectType) lazy val Object_## = newMethod(ObjectClass, nme.HASHHASH, ExprType(IntType), Final) - lazy val Object_== = newMethod(ObjectClass, nme.EQ, methOfAnyRef(BooleanType), Final) - lazy val Object_!= = newMethod(ObjectClass, nme.NE, methOfAnyRef(BooleanType), Final) + lazy val Object_== = newMethod(ObjectClass, nme.EQ, methOfAny(BooleanType), Final) + lazy val Object_!= = newMethod(ObjectClass, nme.NE, methOfAny(BooleanType), Final) lazy val Object_eq = newMethod(ObjectClass, nme.eq, methOfAnyRef(BooleanType), Final) lazy val Object_ne = newMethod(ObjectClass, nme.ne, methOfAnyRef(BooleanType), Final) lazy val Object_isInstanceOf = newT1EmptyParamsMethod(ObjectClass, nme.isInstanceOf_Ob, _ => BooleanType, Final | Synthetic) diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index cce6cc350..c42f0bb36 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -86,10 +86,10 @@ trait TypeOps { this: Context => } /** Normalize a list of parent types of class `cls` that may contain refinements - * to a list of typerefs, by converting all refinements to member + * to a list of typerefs referring to classes, by converting all refinements to member * definitions in scope `decls`. Can add members to `decls` as a side-effect. */ - def normalizeToRefs(parents: List[Type], cls: ClassSymbol, decls: Scope): List[TypeRef] = { + def normalizeToClassRefs(parents: List[Type], cls: ClassSymbol, decls: Scope): List[TypeRef] = { def enterArgBinding(formal: Symbol, info: Type) = { val typeArgFlag = if (formal is Local) TypeArgument else EmptyFlags @@ -144,7 +144,8 @@ trait TypeOps { this: Context => formals = formals.updated(name, tp1.typeParamNamed(name)) normalizeToRef(tp1) case tp: TypeRef => - tp + if (tp.symbol.isAliasType) normalizeToRef(tp.info.bounds.hi) + else tp case ErrorType => defn.AnyClass.typeRef case _ => diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 177a8f21d..0351c948d 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -95,7 +95,7 @@ object UnPickler { case TempPolyType(tps, cinfo) => (tps, cinfo) case cinfo => (Nil, cinfo) } - val parentRefs = ctx.normalizeToRefs(parents, cls, decls) + val parentRefs = ctx.normalizeToClassRefs(parents, cls, decls) for (tparam <- tparams) { val tsym = decls.lookup(tparam.name) if (tsym.exists) tsym.setFlag(TypeParam) diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 1908cbafd..56bd95257 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -365,7 +365,7 @@ class Namer { typer: Typer => // pre-set info, so that parent types can refer to type params cls.info = adjustIfModule(ClassInfo(cls.owner.thisType, cls, Nil, decls, selfInfo)) val parentTypes = parents map parentType - val parentRefs = ctx.normalizeToRefs(parentTypes, cls, decls) + val parentRefs = ctx.normalizeToClassRefs(parentTypes, cls, decls) val parentClsRefs = for ((parentRef, constr) <- parentRefs zip parents) yield checkClassTypeWithStablePrefix(parentRef, constr.pos) -- cgit v1.2.3