diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2009-03-30 12:26:51 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2009-03-30 12:26:51 +0000 |
commit | 8087f9b529ad79a403a29117408632366a7534d9 (patch) | |
tree | 8b4433279a2352ad4ff4914856a709a418ea7fee /src/compiler | |
parent | b62a73e023b4dad90f1712c448fdf9f456b8ebcf (diff) | |
download | scala-8087f9b529ad79a403a29117408632366a7534d9.tar.gz scala-8087f9b529ad79a403a29117408632366a7534d9.tar.bz2 scala-8087f9b529ad79a403a29117408632366a7534d9.zip |
Fixed Java signatures of forwarders for inherit...
Fixed Java signatures of forwarders for inherited members, and
references to scala.Nothing are translated to scala.runtime.Nothing$
(see #1254, #1822, #1555). Moved a Java test that was not run to its
proper subdirectory, to make partest happy.
Diffstat (limited to 'src/compiler')
5 files changed, 32 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 8f17c000ee..cee270e555 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -15,6 +15,7 @@ import scala.collection.mutable.{Map, HashMap, HashSet} import scala.tools.nsc.io.AbstractFile import scala.tools.nsc.symtab._ import scala.tools.nsc.util.{Position, NoPosition} +import scala.tools.nsc.symtab.classfile.ClassfileConstants._ import ch.epfl.lamp.fjbg._ @@ -219,7 +220,7 @@ abstract class GenJVM extends SubComponent { clasz.fields foreach genField clasz.methods foreach genMethod - addGenericSignature(jclass, c.symbol) + addGenericSignature(jclass, c.symbol, c.symbol.owner) addAnnotations(jclass, c.symbol.attributes) emitClass(jclass, c.symbol) @@ -408,10 +409,12 @@ abstract class GenJVM extends SubComponent { nattr } - def addGenericSignature(jmember: JMember, sym: Symbol) { + def addGenericSignature(jmember: JMember, sym: Symbol, owner: Symbol) { if (!sym.hasFlag(Flags.LIFTED | Flags.EXPANDEDNAME | Flags.SYNTHETIC) && settings.target.value == "jvm-1.5") { - erasure.javaSig(sym) match { + val memberTpe = atPhase(currentRun.erasurePhase)(owner.info.memberInfo(sym)) +// println("sym: " + sym.fullNameString + " : " + memberTpe + " sym.info: " + sym.info) + erasure.javaSig(sym, memberTpe) match { case Some(sig) => val index = jmember.getConstantPool().addUtf8(sig).toShort if (settings.debug.value && settings.verbose.value) @@ -531,7 +534,7 @@ abstract class GenJVM extends SubComponent { jclass.addNewField(flags | attributes, javaName(f.symbol), javaType(f.symbol.tpe)); - addGenericSignature(jfield, f.symbol) + addGenericSignature(jfield, f.symbol, clasz.symbol) addAnnotations(jfield, f.symbol.attributes) } @@ -598,7 +601,7 @@ abstract class GenJVM extends SubComponent { genLocalVariableTable(m, jcode); } - addGenericSignature(jmethod, m.symbol) + addGenericSignature(jmethod, m.symbol, clasz.symbol) val (excs, others) = splitAnnotations(m.symbol.attributes, ThrowsAttr) addExceptionsAttribute(jmethod, excs) addAnnotations(jmethod, others) @@ -735,7 +738,7 @@ abstract class GenJVM extends SubComponent { addRemoteException(mirrorMethod, m) // only add generic signature if the method is concrete; bug #1745 if (!m.hasFlag(Flags.DEFERRED)) - addGenericSignature(mirrorMethod, m) + addGenericSignature(mirrorMethod, m, module) val (throws, others) = splitAnnotations(m.attributes, ThrowsAttr) addExceptionsAttribute(mirrorMethod, throws) @@ -1628,9 +1631,9 @@ abstract class GenJVM extends SubComponent { !sym.hasFlag(Flags.JAVA)) "$" else ""; if (sym == definitions.NothingClass) - return "scala.runtime.Nothing$" + return javaName(definitions.RuntimeNothingClass) else if (sym == definitions.NullClass) - return "scala.runtime.Null$" + return javaName(definitions.RuntimeNullClass) if (sym.isClass && !sym.rawowner.isPackageClass && !sym.isModuleClass) { innerClasses = innerClasses + sym; diff --git a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala index b04aabd339..7cee5e5b61 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala @@ -64,7 +64,10 @@ abstract class ClosureElimination extends SubComponent { case (LOAD_LOCAL(x), STORE_LOCAL(y)) => if (x eq y) Some(Nil) else None - case (LOAD_LOCAL(_), DROP(_)) => +// case (STORE_LOCAL(x), LOAD_LOCAL(y)) if (x == y) => +// Some(List(DUP(x.kind), STORE_LOCAL(x))) + + case (LOAD_LOCAL(_), DROP(_)) | (DUP(_), DROP(_)) => Some(Nil) case (BOX(t1), UNBOX(t2)) if (t1 == t2) => diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 6623a41992..4f2e07166f 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -43,6 +43,10 @@ trait Definitions { var NullClass: Symbol = _ var NothingClass: Symbol = _ + + lazy val RuntimeNothingClass = getClass("scala.runtime.Nothing$") + lazy val RuntimeNullClass = getClass("scala.runtime.Null$") + var SingletonClass: Symbol = _ lazy val uncheckedStableClass = getClass("scala.annotation.unchecked.uncheckedStable") lazy val uncheckedVarianceClass = getClass("scala.annotation.unchecked.uncheckedVariance") diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileConstants.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileConstants.scala index 1fc632ef4b..6b16cdddcb 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileConstants.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileConstants.scala @@ -91,6 +91,9 @@ object ClassfileConstants { final val VOID_TAG = 'V' final val TVAR_TAG = 'T' final val ANNOTATION_TAG = '@' + final val SCALA_NOTHING = "scala.runtime.Nothing$" + final val SCALA_NULL = "scala.runtime.Null$" + // tags describing the type of newarray final val T_BOOLEAN = 4 diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 3072d2d465..7485e4ae66 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -156,7 +156,10 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { UnitClass -> VOID_TAG ) - def javaSig(sym: Symbol): Option[String] = atPhase(currentRun.erasurePhase) { + /** The Java signature of type 'info', for symbol sym. The symbol is used to give the right return + * type for constructors. + */ + def javaSig(sym: Symbol, info: Type): Option[String] = atPhase(currentRun.erasurePhase) { def jsig(tp: Type): String = jsig2(false, List(), tp) @@ -194,6 +197,10 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { jsig(ObjectClass.tpe) else if (sym == UnitClass) jsig(BoxedUnitClass.tpe) + else if (sym == NothingClass) + jsig(RuntimeNothingClass.tpe) + else if (sym == NullClass) + jsig(RuntimeNullClass.tpe) else if (isValueClass(sym)) tagOfClass(sym).toString else if (sym.isClass) @@ -238,10 +245,10 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { else jsig(etp) } } - if (needsJavaSig(sym.info)) { + if (needsJavaSig(info)) { try { //println("Java sig of "+sym+" is "+jsig2(true, List(), sym.info))//DEBUG - Some(jsig2(true, List(), sym.info)) + Some(jsig2(true, List(), info)) } catch { case ex: UnknownSig => None } |