diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/classfile/ClassfileConstants.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 13 | ||||
-rw-r--r-- | test/files/pos5/t1186/t1186.java (renamed from test/files/pos5/t1186.java) | 0 | ||||
-rw-r--r-- | test/files/pos5/t1254/t1254.java | 28 |
7 files changed, 60 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 } diff --git a/test/files/pos5/t1186.java b/test/files/pos5/t1186/t1186.java index c1bfcecab8..c1bfcecab8 100644 --- a/test/files/pos5/t1186.java +++ b/test/files/pos5/t1186/t1186.java diff --git a/test/files/pos5/t1254/t1254.java b/test/files/pos5/t1254/t1254.java new file mode 100644 index 0000000000..25b733cf28 --- /dev/null +++ b/test/files/pos5/t1254/t1254.java @@ -0,0 +1,28 @@ +/* Taken from ticket #1254. Tests Java signatures in mirror classes and that + Nothing is translated to Nothing$. +*/ + +import scala.None; + +// This compiles with javac but fails with Eclipse java compiler: +// 'The type scala.Nothing cannot be resolved. It is indirectly referenced from required .class files' +class NothingBug3 { + public NothingBug3() { + scala.Option<?> o = scala.None$.MODULE$; + + test(o); + None.toLeft(new scala.Function0<Integer>() { + public Integer apply() { return 0; } + }); + } + + public <T>void test(scala.Option<T> f) {} +} + +// This compiles with javac but fails with Eclipse java compiler: +// 'The type scala.Nothing cannot be resolved. It is indirectly referenced from required .class files' +class NothingBug4 { + public NothingBug4() { + scala.Option o = scala.None$.MODULE$; + } +} |