From 482cf0e2ef0f630a7827fdfacf684449bf04596b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Dec 2009 12:53:20 +0000 Subject: small cleanups. no review necessary. --- src/compiler/scala/tools/nsc/symtab/Types.scala | 4 +-- .../scala/tools/nsc/transform/Erasure.scala | 30 +++++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 7350410eeb..c4772b6407 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -139,8 +139,6 @@ trait Types { } } - - /** A map from lists to compound types that have the given list as parents. * This is used to avoid duplication in the computation of base type sequences and baseClasses. * It makes use of the fact that these two operations depend only on the parents, @@ -1763,7 +1761,7 @@ A type's typeSymbol should never be inspected directly. packagePrefix + str else if (sym.isModuleClass) objectPrefix + str - else if (sym.isAnonymousClass && sym.isInitialized && !settings.debug.value) + else if (sym.isAnonymousClass && sym.isInitialized && !settings.debug.value && !phase.erasedTypes) thisInfo.parents.mkString(" with ") + { if (sym.isStructuralRefinement) ((decls.toList filter { entry => diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 9db88af6c6..1fa81c8776 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -116,6 +116,22 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. * */ val erasure = new TypeMap { + + // Compute the erasure of the intersection type with given `parents` according to new spec. + private def intersectionErasure(parents: List[Type]): Type = + if (parents.isEmpty) erasedTypeRef(ObjectClass) + else { + // implement new spec for erasure of refined types. + val psyms = parents map (_.typeSymbol) + def isUnshadowed(psym: Symbol) = + !(psyms exists (qsym => (psym ne qsym) && (qsym isNonBottomSubClass psym))) + val cs = parents.iterator.filter { p => // isUnshadowed is a bit expensive, so try classes first + val psym = p.typeSymbol + psym.isClass && !psym.isTrait && isUnshadowed(psym) + } + apply((if (cs.hasNext) cs else parents.iterator.filter(p => isUnshadowed(p.typeSymbol))).next()) + } + def apply(tp: Type): Type = { tp match { case ConstantType(_) => @@ -129,6 +145,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. else typeRef(apply(pre), sym, args map this) else if (sym == AnyClass || sym == AnyValClass || sym == SingletonClass) erasedTypeRef(ObjectClass) else if (sym == UnitClass) erasedTypeRef(BoxedUnitClass) + else if (sym.isRefinementClass) intersectionErasure(tp.parents) else if (sym.isClass) typeRef(apply(rebindInnerClass(pre, sym)), sym, List()) // #2585 else apply(sym.info) // alias type or abstract type case PolyType(tparams, restpe) => @@ -145,18 +162,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. else apply(restpe)) case RefinedType(parents, decls) => - if (parents.isEmpty) erasedTypeRef(ObjectClass) - else { - // implement new spec for erasure of refined types. - val psyms = parents map (_.typeSymbol) - def isUnshadowed(psym: Symbol) = - !(psyms exists (qsym => (psym ne qsym) && (qsym isNonBottomSubClass psym))) - val cs = parents.iterator.filter { p => // isUnshadowed is a bit expensive, so try classes first - val psym = p.typeSymbol - psym.isClass && !psym.isTrait && isUnshadowed(psym) - } - apply((if (cs.hasNext) cs else parents.iterator.filter(p => isUnshadowed(p.typeSymbol))).next()) - } + intersectionErasure(parents) case AnnotatedType(_, atp, _) => apply(atp) case ClassInfoType(parents, decls, clazz) => -- cgit v1.2.3