From bc9a3475f308e78de193e4072f11e2edb7f7a72b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 6 Mar 2011 10:07:51 +0000 Subject: Re-enabling the disabled signature test along w... Re-enabling the disabled signature test along with changes which allow it to pass. Closes #4238 again, no review. (But would anyone like to expand the signature tests? Great idea, extempore!) --- .../scala/tools/nsc/transform/Erasure.scala | 47 ++++++++++++---------- src/compiler/scala/tools/nsc/util/Tracer.scala | 3 +- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index a6c862c19d..dcc6ab044c 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -202,14 +202,15 @@ abstract class Erasure extends AddInterfaces private def needsJavaSig(tp: Type) = !settings.Ynogenericsig.value && NeedsSigCollector.collect(tp) // only refer to type params that will actually make it into the sig, this excludes: - // * higher-order type parameters (aka !sym.owner.isTypeParameterOrSkolem) + // * higher-order type parameters // * parameters of methods - // * type members not visible in the enclosing template - private def isTypeParameterInSig(sym: Symbol, nestedIn: Symbol) = ( - !sym.owner.isTypeParameterOrSkolem && + // * type members not visible in an enclosing template + private def isTypeParameterInSig(sym: Symbol, initialSymbol: Symbol) = ( + !sym.isHigherOrderTypeParameter && sym.isTypeParameterOrSkolem && - (sym isNestedIn nestedIn) + initialSymbol.enclClassChain.exists(sym isNestedIn _) ) + // Ensure every '.' in the generated signature immediately follows // a close angle bracket '>'. Any which do not are replaced with '$'. // This arises due to multiply nested classes in the face of the @@ -274,8 +275,10 @@ abstract class Erasure extends AddInterfaces if (unboundedGenericArrayLevel(tp) == 1) jsig(ObjectClass.tpe) else ARRAY_TAG.toString+(args map jsig).mkString } - else if (isTypeParameterInSig(sym, sym0.enclClass)) + else if (isTypeParameterInSig(sym, sym0)) { + assert(!sym.isAliasType, "Unexpected alias type: " + sym) TVAR_TAG.toString+sym.name+";" + } else if (sym == AnyClass || sym == AnyValClass || sym == SingletonClass) jsig(ObjectClass.tpe) else if (sym == UnitClass) @@ -288,21 +291,23 @@ abstract class Erasure extends AddInterfaces jsig(ObjectClass.tpe) else if (sym.isClass) { val preRebound = pre.baseType(sym.owner) // #2585 - dotCleanup( - ( - if (needsJavaSig(preRebound)) { - val s = jsig(preRebound) - if (s.charAt(0) == 'L') s.substring(0, s.length - 1) + classSigSuffix + traceSig.seq("sym.isClass", Seq(sym.ownerChain, preRebound, sym0.enclClassChain)) { + dotCleanup( + ( + if (needsJavaSig(preRebound)) { + val s = jsig(preRebound) + if (s.charAt(0) == 'L') s.substring(0, s.length - 1) + classSigSuffix + else classSig + } else classSig - } - else classSig - ) + ( - if (args.isEmpty) "" else - "<"+(args map argSig).mkString+">" - ) + ( - ";" + ) + ( + if (args.isEmpty) "" else + "<"+(args map argSig).mkString+">" + ) + ( + ";" + ) ) - ) + } } else jsig(erasure(tp)) case PolyType(tparams, restpe) => @@ -338,13 +343,13 @@ abstract class Erasure extends AddInterfaces else jsig(etp) } } - // traceSig("javaSig", sym0, info) { + traceSig.seq("javaSig", Seq(sym0, info)) { if (needsJavaSig(info)) { try Some(jsig2(true, Nil, info)) catch { case ex: UnknownSig => None } } else None - // } + } } class UnknownSig extends Exception diff --git a/src/compiler/scala/tools/nsc/util/Tracer.scala b/src/compiler/scala/tools/nsc/util/Tracer.scala index c5d3fd3753..17be05a4d6 100644 --- a/src/compiler/scala/tools/nsc/util/Tracer.scala +++ b/src/compiler/scala/tools/nsc/util/Tracer.scala @@ -22,7 +22,7 @@ class Tracer(enabled: () => Boolean) { p(ind("" + x)) x } - def apply[T](name: String, args: Any*)(body: => T): T = { + def seq[T](name: String, args: => Seq[Any])(body: => T): T = { if (enabled()) { p(ind("%s(%s) = {\n".format(name, args mkString ", "))) try indented(pin(body)) @@ -30,6 +30,7 @@ class Tracer(enabled: () => Boolean) { } else body } + def apply[T](name: String, args: Any*)(body: => T): T = seq(name, args.toSeq)(body) } object Tracer { -- cgit v1.2.3