From edfd93e295e746fa2b7e37d10b65b3b3fc41ab65 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 20 Jan 2013 09:17:53 -0800 Subject: [PATCH] Almost-fix for SI-3452. At this commit ant test-opt has two test failures: test/files/pos/javaReadsSigs [FAILED] test/files/run/t4238 [FAILED] Fix for wrong bytecode in forwarders. This took me so long to figure out I can't even tell you. Partly because there were two different bugs, one which only arose for trait forwarders and one for mirror class forwarders, and every time I'd make one set of tests work another set would start failing. The runtime failures associated with these bugs were fairly well hidden because you usually have to go through java to encounter them: scala doesn't pay that much attention to generic signatures, so they can be wrong and scala might still generate correct code. But java is not so lucky. Bug #1) During mixin composition, classes which extend traits receive forwarders to the implementations. An attempt was made to give these the correct info (in method "cloneBeforeErasure") but it was prone to giving the wrong answer, because: the key attribute which the forwarder must capture is what the underlying method will erase to *where the implementation is*, not how it appears to the class which contains it. That means the signature of the forwarder must be no more precise than the signature of the inherited implementation unless additional measures will be taken. This subtle difference will put on an unsubtle show for you in test run/t3452.scala. trait C[T] trait Search[M] { def search(input: M): C[Int] = null } object StringSearch extends Search[String] { } StringSearch.search("test"); // java // java.lang.NoSuchMethodError: StringSearch.search(Ljava/lang/String;)LC; Before/after this commit: < signature search (Ljava/lang/String;)LC; --- > signature search (Ljava/lang/Object;)LC; Bug #2) The same principle is at work, at a different location. During genjvm, objects without declared companion classes are given static forwarders in the corresponding class, e.g. object Foo { def bar = 5 } which creates these classes (taking minor liberties): class Foo$ { static val MODULE$ = new Foo$ ; def bar = 5 } class Foo { static def bar = Foo$.MODULE$.bar } In generating these, genjvm circumvented the usual process whereby one creates a symbol and gives it an info, preferring to target the bytecode directly. However generic signatures are calculated from symbol info (in this case reusing the info from the module class.) Lacking even the attempt which was being made in mixin to "clone before erasure", we would have runtime failures of this kind: abstract class Foo { type T def f(x: T): List[T] = List() } object Bar extends Foo { type T = String } Bar.f(""); // java // java.lang.NoSuchMethodError: Bar.f(Ljava/lang/String;)Lscala/collection/immutable/List; Before/after this commit: < signature f (Ljava/lang/String;)Lscala/collection/immutable/List; --- > signature f (Ljava/lang/Object;)Lscala/collection/immutable/List; Closes SI-3452. --- .../scala/tools/nsc/backend/jvm/GenASM.scala | 13 +- .../scala/tools/nsc/transform/Mixin.scala | 28 +++-- test/files/neg/t4749.scala | 8 +- test/files/run/mixin-signatures.check | 59 +++++++++ test/files/run/mixin-signatures.scala | 105 ++++++++++++++++ test/files/run/t3452.check | 1 + test/files/run/t3452.scala | 21 ++++ test/files/run/t3452a.check | 1 + test/files/run/t3452a/J_2.java | 5 + test/files/run/t3452a/S_1.scala | 24 ++++ test/files/run/t3452a/S_3.scala | 5 + test/files/run/t3452b.check | 1 + test/files/run/t3452b/J_2.java | 5 + test/files/run/t3452b/S_1.scala | 10 ++ test/files/run/t3452b/S_3.scala | 5 + test/files/run/t3452c.check | 8 ++ test/files/run/t3452c.scala | 113 ++++++++++++++++++ test/support/java-tests.txt | 97 +++++++++++++++ tools/compare-java-sigs | 56 +++++++++ 19 files changed, 553 insertions(+), 12 deletions(-) create mode 100644 test/files/run/mixin-signatures.check create mode 100644 test/files/run/mixin-signatures.scala create mode 100644 test/files/run/t3452.check create mode 100644 test/files/run/t3452.scala create mode 100644 test/files/run/t3452a.check create mode 100644 test/files/run/t3452a/J_2.java create mode 100644 test/files/run/t3452a/S_1.scala create mode 100644 test/files/run/t3452a/S_3.scala create mode 100644 test/files/run/t3452b.check create mode 100644 test/files/run/t3452b/J_2.java create mode 100644 test/files/run/t3452b/S_1.scala create mode 100644 test/files/run/t3452b/S_3.scala create mode 100644 test/files/run/t3452c.check create mode 100644 test/files/run/t3452c.scala create mode 100644 test/support/java-tests.txt create mode 100644 tools/compare-java-sigs diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 45c366cc6983..6a911db2ab83 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -1063,7 +1063,18 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { ) // TODO needed? for(ann <- m.annotations) { ann.symbol.initialize } - val jgensig = if (m.isDeferred) null else getGenericSignature(m, module); // only add generic signature if method concrete; bug #1745 + val jgensig = ( + // only add generic signature if method concrete; bug #1745 + if (m.isDeferred) null else { + val clazz = module.linkedClassOfClass + val m1 = ( + if ((clazz.info member m.name) eq NoSymbol) + enteringErasure(m.cloneSymbol(clazz, Flags.METHOD | Flags.STATIC)) + else m + ) + getGenericSignature(m1, clazz) + } + ) addRemoteExceptionAnnot(isRemoteClass, hasPublicBitSet(flags), m) val (throws, others) = m.annotations partition (_.symbol == ThrowsClass) val thrownExceptions: List[String] = getExceptions(throws) diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 3e5ac6922e5a..06fad5e27dbd 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -161,6 +161,12 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { debuglog("new member of " + clazz + ":" + member.defString) clazz.info.decls enter member setFlag MIXEDIN } + /** Warning: subtle issues at play! + * The info of the cloned symbol used to be calculated as: + * (clazz.thisType baseType mixinClass) memberInfo mixinMember + * This is not correct! See test run/t3452b for an example + * of runtime failure. + */ def cloneAndAddMember(mixinClass: Symbol, mixinMember: Symbol, clazz: Symbol): Symbol = addMember(clazz, cloneBeforeErasure(mixinClass, mixinMember, clazz)) @@ -172,17 +178,19 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { // implementation class, as it's a clone that was made after erasure, and thus it does not // know its info at the beginning of erasure anymore. // Optimize: no need if mixinClass has no typeparams. - mixinMember cloneSymbol clazz modifyInfo (info => - if (mixinClass.typeParams.isEmpty) info - else (clazz.thisType baseType mixinClass) memberInfo mixinMember - ) + val sym = mixinMember cloneSymbol clazz + // Optimize: no need if mixinClass has no typeparams. + if (mixinClass.typeParams.isEmpty) sym + else sym modifyInfo (_.asSeenFrom(clazz.thisType, clazz)) } // clone before erasure got rid of type info we'll need to generate a javaSig // now we'll have the type info at (the beginning of) erasure in our history, // and now newSym has the info that's been transformed to fit this period // (no need for asSeenFrom as phase.erasedTypes) // TODO: verify we need the updateInfo and document why - newSym updateInfo (mixinMember.info cloneInfo newSym) + // addMember(clazz, newSym) + newSym + // updateInfo (mixinMember.info cloneInfo newSym) } def needsExpandedSetterName(field: Symbol) = !field.isLazy && ( @@ -273,8 +281,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { val imember = member overriddenSymbol mixinInterface imember overridingSymbol clazz match { case NoSymbol => - if (clazz.info.findMember(member.name, 0, lateDEFERRED, false).alternatives contains imember) - cloneAndAddMixinMember(mixinInterface, imember).asInstanceOf[TermSymbol] setAlias member + if (clazz.info.findMember(member.name, 0, lateDEFERRED, false).alternatives contains imember) { + val forwarder = cloneAndAddMixinMember(mixinInterface, imember).asInstanceOf[TermSymbol] setAlias member + log("Adding forwarder from %s to %s during mixin:\n before erasure: %s => %s\n after erasure: %s => %s".format( + clazz, member.owner, + enteringErasure(forwarder.defString), enteringErasure(member.defString), + forwarder.defString, member.defString) + ) + } case _ => } } diff --git a/test/files/neg/t4749.scala b/test/files/neg/t4749.scala index 0973c360978b..7d8c1ceaae04 100644 --- a/test/files/neg/t4749.scala +++ b/test/files/neg/t4749.scala @@ -29,6 +29,10 @@ package bippy { class Fail6 { def main = "bippy" } + trait FailBippy[T] { + def main(args: Array[String]): T = null.asInstanceOf[T] + } + object Fail7 extends FailBippy[Unit] { } object Win1 { def main(args: Array[String]): Unit = () @@ -36,9 +40,5 @@ package bippy { object Win2 extends Bippy[Unit] { override def main(args: Array[String]): Unit = () } - trait WinBippy[T] { - def main(args: Array[String]): T = null.asInstanceOf[T] - } - object Win3 extends WinBippy[Unit] { } } diff --git a/test/files/run/mixin-signatures.check b/test/files/run/mixin-signatures.check new file mode 100644 index 000000000000..4ea32ec206a2 --- /dev/null +++ b/test/files/run/mixin-signatures.check @@ -0,0 +1,59 @@ +class Test$bar1$ { + public java.lang.String Test$bar1$.f(java.lang.Object) + public java.lang.Object Test$bar1$.f(java.lang.Object) + public java.lang.String Test$bar1$.g(java.lang.String) + public java.lang.Object Test$bar1$.g(java.lang.Object) + public java.lang.String Test$bar1$.g(java.lang.Object) + public java.lang.Object Test$bar1$.h(java.lang.Object) +} + +class Test$bar2$ { + public java.lang.Object Test$bar2$.f(java.lang.String) + public java.lang.Object Test$bar2$.f(java.lang.Object) + public java.lang.String Test$bar2$.g(java.lang.String) + public java.lang.Object Test$bar2$.g(java.lang.Object) + public java.lang.Object Test$bar2$.g(java.lang.String) + public java.lang.Object Test$bar2$.h(java.lang.Object) +} + +class Test$bar3$ { + public java.lang.String Foo3.f(java.lang.Object) + generic: public java.lang.String Foo3.f(T) + public java.lang.Object Foo3.f(java.lang.Object) + public java.lang.String Test$bar3$.g(java.lang.String) + public java.lang.Object Test$bar3$.g(java.lang.Object) + public java.lang.String Test$bar3$.g(java.lang.Object) + public java.lang.Object Foo3.h(java.lang.Object) +} + +class Test$bar4$ { + public java.lang.Object Foo4.f(java.lang.String) + generic: public R Foo4.f(java.lang.String) + public java.lang.Object Foo4.f(java.lang.Object) + public java.lang.String Test$bar4$.g(java.lang.String) + public java.lang.Object Test$bar4$.g(java.lang.Object) + public java.lang.Object Test$bar4$.g(java.lang.String) + public java.lang.Object Foo4.h(java.lang.Object) +} + +class Test$bar5$ { + public java.lang.String Test$bar5$.f(java.lang.String) + public java.lang.Object Test$bar5$.f(java.lang.Object) + public java.lang.String Test$bar5$.f(java.lang.Object) + public java.lang.Object Test$bar5$.f(java.lang.String) + public java.lang.String Test$bar5$.g(java.lang.String) + public java.lang.Object Test$bar5$.g(java.lang.String) + public java.lang.Object Test$bar5$.g(java.lang.Object) + public java.lang.String Test$bar5$.g(java.lang.Object) + public java.lang.Object Test$bar5$.h(java.lang.Object) +} + +class Foo1$class { + public static java.lang.String Foo1$class.f(Foo1,java.lang.Object) +} + +class Foo2$class { + public static java.lang.Object Foo2$class.f(Foo2,java.lang.String) +} + +000000000000000000000000000000000000 diff --git a/test/files/run/mixin-signatures.scala b/test/files/run/mixin-signatures.scala new file mode 100644 index 000000000000..24642aed5a38 --- /dev/null +++ b/test/files/run/mixin-signatures.scala @@ -0,0 +1,105 @@ +trait Base[T, R] { + def f(x: T): R + def g(x: T): R + def h(x: T): R = null.asInstanceOf[R] +} + +trait Foo1[T] extends Base[T, String] { + def f(x: T): String = null + def g(x: T): String +} +trait Foo2[R] extends Base[String, R] { + def f(x: String): R = { print(x.length) ; null.asInstanceOf[R] } + def g(x: String): R +} +abstract class Foo3[T] extends Base[T, String] { + def f(x: T): String = "" + def g(x: T): String +} +abstract class Foo4[R] extends Base[String, R] { + def f(x: String): R = { print(x.length) ; null.asInstanceOf[R] } + def g(x: String): R +} + +object Test { + object bar1 extends Foo1[String] { def g(x: String): String = { print(x.length) ; "" } } + object bar2 extends Foo2[String] { def g(x: String): String = { print(x.length) ; "" } } + object bar3 extends Foo3[String] { def g(x: String): String = { print(x.length) ; "" } } + object bar4 extends Foo4[String] { def g(x: String): String = { print(x.length) ; "" } } + + // Notice that in bar5, f and g require THREE bridges, because the final + // implementation is (String)String, but: + // + // inherited abstract signatures: T(R), (T)String, and (String)R + // which erase to: (Object)Object, (Object)String, and (String)Object + // + // each of which must be bridged to the actual (String)String implementation. + // + // public java.lang.String Test$bar5$.g(java.lang.String) + // public java.lang.Object Test$bar5$.g(java.lang.String) + // public java.lang.Object Test$bar5$.g(java.lang.Object) + // public java.lang.String Test$bar5$.g(java.lang.Object) + object bar5 extends Foo1[String] with Foo2[String] { + override def f(x: String): String = { print(x.length) ; x } + def g(x: String): String = { print(x.length) ; x } + } + + final def m1[T, R](x: Base[T, R], y: T) = { x.f(y) ; x.g(y) ; x.h(y) } + final def m2[T](x: Base[T, String], y: T) = { x.f(y) ; x.g(y) ; x.h(y) } + final def m3[R](x: Base[String, R]) = { x.f("") ; x.g("") ; x.h("") } + final def m4(x: Base[String, String]) = { x.f("") ; x.g("") ; x.h("") } + + final def m11[T](x: Foo1[T], y: T) = { x.f(y) ; x.g(y) ; x.h(y) } + final def m12(x: Foo1[String]) = { x.f("") ; x.g("") ; x.h("") } + final def m21[T](x: Foo2[T], y: T) = { x.f("") ; x.g("") ; x.h("") } + final def m22(x: Foo2[String]) = { x.f("") ; x.g("") ; x.h("") } + final def m31[T](x: Foo3[T], y: T) = { x.f(y) ; x.g(y) ; x.h(y) } + final def m32(x: Foo3[String]) = { x.f("") ; x.g("") ; x.h("") } + final def m41[T](x: Foo4[T], y: T) = { x.f("") ; x.g("") ; x.h("") } + final def m42(x: Foo4[String]) = { x.f("") ; x.g("") ; x.h("") } + + def go = { + m1(bar1, "") ; m2(bar1, "") ; m3(bar1) ; m4(bar1) + m1(bar2, "") ; m2(bar2, "") ; m3(bar2) ; m4(bar2) + m1(bar3, "") ; m2(bar3, "") ; m3(bar3) ; m4(bar3) + m1(bar4, "") ; m2(bar4, "") ; m3(bar4) ; m4(bar4) + + m11(bar1, "") ; m12(bar1) + m21(bar2, "") ; m22(bar2) + m31(bar3, "") ; m32(bar3) + m41(bar4, "") ; m42(bar4) + "" + } + + def flagsString(m: java.lang.reflect.Method) = { + val str = List( + if (m.isBridge) "" else "", + if (m.isSynthetic) "" else "" + ) filterNot (_ == "") mkString " " + + if (str == "") "" else " " + str + // + // val flags = scala.reflect.internal.ClassfileConstants.toScalaMethodFlags(m.getModifiers()) + // scala.tools.nsc.symtab.Flags.flagsToString(flags) + } + + def show(clazz: Class[_]) { + print(clazz + " {") + clazz.getMethods.sortBy(x => (x.getName, x.isBridge)) filter (_.getName.length == 1) foreach { m => + print("\n " + m + flagsString(m)) + if ("" + m != "" + m.toGenericString) { + print("\n generic: " + m.toGenericString) + } + } + println("\n}") + println("") + } + def show(x: AnyRef) { show(x.getClass) } + def show(x: String) { show(Class.forName(x)) } + + def main(args: Array[String]): Unit = { + List(bar1, bar2, bar3, bar4, bar5) foreach show + List("Foo1$class", "Foo2$class") foreach show + println(go) + } +} \ No newline at end of file diff --git a/test/files/run/t3452.check b/test/files/run/t3452.check new file mode 100644 index 000000000000..b8626c4cff28 --- /dev/null +++ b/test/files/run/t3452.check @@ -0,0 +1 @@ +4 diff --git a/test/files/run/t3452.scala b/test/files/run/t3452.scala new file mode 100644 index 000000000000..253fc93cfaf0 --- /dev/null +++ b/test/files/run/t3452.scala @@ -0,0 +1,21 @@ +trait IStringPair[T] { + def a : String + def b : String + def build(a : String, b : String) : T + def cat(that : IStringPair[T]) = build(this.a + that.a, this.b + that.b) + override def toString = a + b +} + +class StringPair(val a : String, val b : String) extends IStringPair[StringPair] { + def build(a : String, b : String) = new StringPair(a, b) + def len = a.length + b.length +} + +object Test { + def main(args: Array[String]): Unit = { + val a = new StringPair("A", "B") + val b = new StringPair("1", "2") + val c = a cat b + println(c.len) + } +} diff --git a/test/files/run/t3452a.check b/test/files/run/t3452a.check new file mode 100644 index 000000000000..9ff787eb8623 --- /dev/null +++ b/test/files/run/t3452a.check @@ -0,0 +1 @@ +BulkSearch.searchFor called. diff --git a/test/files/run/t3452a/J_2.java b/test/files/run/t3452a/J_2.java new file mode 100644 index 000000000000..62057ffe614d --- /dev/null +++ b/test/files/run/t3452a/J_2.java @@ -0,0 +1,5 @@ +public class J_2 { + public static void main(String[] args) { + BulkSearchInstance.searchFor(new UpRelation()); + } +} diff --git a/test/files/run/t3452a/S_1.scala b/test/files/run/t3452a/S_1.scala new file mode 100644 index 000000000000..791faf42fa40 --- /dev/null +++ b/test/files/run/t3452a/S_1.scala @@ -0,0 +1,24 @@ +abstract class BulkSearch { + type R <: Row + type Rel <: Relation [R] + type Corr <: Correspondence[R] + + def searchFor(input: Rel): Mapping[Corr] = { println("BulkSearch.searchFor called.") ; null } +} + +object BulkSearchInstance extends BulkSearch { + type R = UpRow + type Rel = UpRelation + type Corr = UpCorrespondence +} + +class Row +class UpRow extends Row + +class Relation [R <: Row] +class UpRelation extends Relation [UpRow] + +class Correspondence [R <: Row] +class UpCorrespondence extends Correspondence [UpRow] + +class Mapping[MC <: Correspondence[_]] diff --git a/test/files/run/t3452a/S_3.scala b/test/files/run/t3452a/S_3.scala new file mode 100644 index 000000000000..aaa898dcde94 --- /dev/null +++ b/test/files/run/t3452a/S_3.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + J_2.main(args) + } +} diff --git a/test/files/run/t3452b.check b/test/files/run/t3452b.check new file mode 100644 index 000000000000..4f9ed634b4d2 --- /dev/null +++ b/test/files/run/t3452b.check @@ -0,0 +1 @@ +Search received: test diff --git a/test/files/run/t3452b/J_2.java b/test/files/run/t3452b/J_2.java new file mode 100644 index 000000000000..24c27b88bd53 --- /dev/null +++ b/test/files/run/t3452b/J_2.java @@ -0,0 +1,5 @@ +public class J_2 { + public static void j() { + StringSearch.search("test"); + } +} diff --git a/test/files/run/t3452b/S_1.scala b/test/files/run/t3452b/S_1.scala new file mode 100644 index 000000000000..3ab19ed031d5 --- /dev/null +++ b/test/files/run/t3452b/S_1.scala @@ -0,0 +1,10 @@ +trait Search[M] { + def search(input: M): C[Int] = { + println("Search received: " + input) + null + } +} + +object StringSearch extends Search[String] + +trait C[T] diff --git a/test/files/run/t3452b/S_3.scala b/test/files/run/t3452b/S_3.scala new file mode 100644 index 000000000000..102b433f478c --- /dev/null +++ b/test/files/run/t3452b/S_3.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + J_2.j() + } +} diff --git a/test/files/run/t3452c.check b/test/files/run/t3452c.check new file mode 100644 index 000000000000..ab47181198de --- /dev/null +++ b/test/files/run/t3452c.check @@ -0,0 +1,8 @@ +3 +3 +3 +3 +3 +3 +3 +3 diff --git a/test/files/run/t3452c.scala b/test/files/run/t3452c.scala new file mode 100644 index 000000000000..2c55767abc52 --- /dev/null +++ b/test/files/run/t3452c.scala @@ -0,0 +1,113 @@ +trait Base[A, B, C] { + def f(x: A, y: B, z: C): Unit + def g(x: A, y: B, z: C) = f(x, y, z) + def h(x: A, y: B, z: C) = g(x, y, z) +} + +trait D1[B, C] extends Base[String, B, C] +trait D2[A, B] extends Base[A, B, String] +trait D3[A, C] extends Base[A, String, C] +trait D4[A] extends Base[A, String, String] +trait D5[B] extends Base[String, B, String] +trait D6[C] extends Base[String, String, C] +trait D7 extends Base[String, String, String] + +trait E1[B, C] extends Base[String, B, C] { def f(x: String, y: B, z: C): Unit ; override def h(x: String, y: B, z: C) = g(x, y, z) } +trait E2[A, B] extends Base[A, B, String] { def f(x: A, y: B, z: String): Unit ; override def h(x: A, y: B, z: String) = g(x, y, z) } +trait E3[A, C] extends Base[A, String, C] { def f(x: A, y: String, z: C): Unit ; override def h(x: A, y: String, z: C) = g(x, y, z) } +trait E4[A] extends Base[A, String, String] { def f(x: A, y: String, z: String): Unit ; override def h(x: A, y: String, z: String) = g(x, y, z) } +trait E5[B] extends Base[String, B, String] { def f(x: String, y: B, z: String): Unit ; override def h(x: String, y: B, z: String) = g(x, y, z) } +trait E6[C] extends Base[String, String, C] { def f(x: String, y: String, z: C): Unit ; override def h(x: String, y: String, z: C) = g(x, y, z) } +trait E7 extends Base[String, String, String] { def f(x: String, y: String, z: String): Unit ; override def h(x: String, y: String, z: String) = g(x, y, z) } + +trait F1[B, C] extends Base[String, B, C] { def f(x: String, y: B, z: C): Unit = println(x.length) } +trait F2[A, B] extends Base[A, B, String] { def f(x: A, y: B, z: String): Unit = println(z.length) } +trait F3[A, C] extends Base[A, String, C] { def f(x: A, y: String, z: C): Unit = println(y.length) } +trait F4[A] extends Base[A, String, String] { def f(x: A, y: String, z: String): Unit = println(y.length) } +trait F5[B] extends Base[String, B, String] { def f(x: String, y: B, z: String): Unit = println(x.length) } +trait F6[C] extends Base[String, String, C] { def f(x: String, y: String, z: C): Unit = println(x.length) } +trait F7 extends Base[String, String, String] { def f(x: String, y: String, z: String): Unit = println(x.length) } + +abstract class DBag extends D1[String, String] with D2[String, String] with D3[String, String] with D4[String] with D5[String] with D6[String] with D7 { + def f(x: String, y: String, z: String) = println(x.length + y.length + z.length) +} +abstract class EBag extends E1[String, String] with E2[String, String] with E3[String, String] with E4[String] with E5[String] with E6[String] with E7 { + def f(x: String, y: String, z: String) = println(x.length + y.length + z.length) +} +abstract class FBag extends F1[String, String] with F2[String, String] with F3[String, String] with F4[String] with F5[String] with F6[String] with F7 { + override def f(x: String, y: String, z: String) = println(x.length + y.length + z.length) +} + +abstract class GBag1[A, B] extends Base[A, B, String] with D2[A, B] { + def f(x: A, y: B, z: String) = println(z.length) +} +abstract class GBag2[A] extends GBag1[A, String] with D4[A] { + override def f(x: A, y: String, z: String) = println(z.length) +} +abstract class GBag3 extends GBag2[String] with D7 { + override def f(x: String, y: String, z: String) = println(z.length) +} +class GBag extends GBag3 with D2[String, String] with D3[String, String] with D4[String] with D5[String] with D6[String] with D7 { +} + +object Test { + def f0(x: Base[String, String, String]) = x.f("a", "b", "c") + def f1(x: D1[String, String]) = x.f("a", "b", "c") + def f2(x: D2[String, String]) = x.f("a", "b", "c") + def f3(x: D3[String, String]) = x.f("a", "b", "c") + def f4(x: D4[String]) = x.f("a", "b", "c") + def f5(x: D5[String]) = x.f("a", "b", "c") + def f6(x: D6[String]) = x.f("a", "b", "c") + def f7(x: D7) = x.f("a", "b", "c") + + def main(args: Array[String]): Unit = { + val x = new DBag { } + f0(x) + f1(x) + f2(x) + f3(x) + f4(x) + f5(x) + f6(x) + f7(x) + } +} + +object TestE { + def f0(x: Base[String, String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f1(x: E1[String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f2(x: E2[String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f3(x: E3[String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f4(x: E4[String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f5(x: E5[String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f6(x: E6[String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f7(x: E7) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + + def main(args: Array[String]): Unit = { + val x = new EBag { } + f0(x) + f1(x) + f2(x) + f3(x) + f4(x) + f5(x) + f6(x) + f7(x) + } +} + + +object TestG { + def f0(x: Base[String, String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f1(x: GBag1[String, String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f2(x: GBag2[String]) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + def f3(x: GBag3) = { x.f("a", "b", "c") ; x.g("a", "b", "c") ; x.h("a", "b", "c") } + + def main(args: Array[String]): Unit = { + val x = new GBag { } + f0(x) + f1(x) + f2(x) + f3(x) + } +} diff --git a/test/support/java-tests.txt b/test/support/java-tests.txt new file mode 100644 index 000000000000..e0a3fddab33d --- /dev/null +++ b/test/support/java-tests.txt @@ -0,0 +1,97 @@ +test/files/buildmanager/t2280 +test/files/buildmanager/t3045 +test/files/buildmanager/t3133 +test/files/jvm/deprecation +test/files/jvm/t1143-2 +test/files/jvm/t1342 +test/files/jvm/t1464 +test/files/jvm/t2470 +test/files/jvm/t2570 +test/files/jvm/t2585 +test/files/jvm/t3003 +test/files/jvm/t3415 +test/files/jvm/ticket2163 +test/files/jvm/ticket4283 +test/files/jvm/varargs +test/files/neg/abstract-class-error +test/files/neg/java-access-neg +test/files/neg/primitive-sigs-1 +test/files/neg/protected-static-fail +test/files/neg/t0673 +test/files/neg/t1548 +test/files/neg/t3663 +test/files/neg/t3757 +test/files/neg/t4851 +test/files/pos/chang +test/files/pos/ilya +test/files/pos/ilya2 +test/files/pos/java-access-pos +test/files/pos/javaReadsSigs +test/files/pos/protected-static +test/files/pos/raw-map +test/files/pos/signatures +test/files/pos/super +test/files/pos/t0288 +test/files/pos/t0695 +test/files/pos/t1101 +test/files/pos/t1102 +test/files/pos/t1150 +test/files/pos/t1152 +test/files/pos/t1176 +test/files/pos/t1186 +test/files/pos/t1196 +test/files/pos/t1197 +test/files/pos/t1203 +test/files/pos/t1230 +test/files/pos/t1231 +test/files/pos/t1232 +test/files/pos/t1235 +test/files/pos/t1254 +test/files/pos/t1263 +test/files/pos/t1409 +test/files/pos/t1459 +test/files/pos/t1642 +test/files/pos/t1711 +test/files/pos/t1745 +test/files/pos/t1751 +test/files/pos/t1782 +test/files/pos/t1836 +test/files/pos/t1840 +test/files/pos/t1937 +test/files/pos/t2377 +test/files/pos/t2409 +test/files/pos/t2413 +test/files/pos/t2433 +test/files/pos/t2464 +test/files/pos/t2569 +test/files/pos/t2868 +test/files/pos/t294 +test/files/pos/t2940 +test/files/pos/t2956 +test/files/pos/t3249 +test/files/pos/t3349 +test/files/pos/t3404 +test/files/pos/t3429 +test/files/pos/t3486 +test/files/pos/t3521 +test/files/pos/t3567 +test/files/pos/t3622 +test/files/pos/t3642 +test/files/pos/t3938 +test/files/pos/t3946 +test/files/pos/t4402 +test/files/pos/t4603 +test/files/pos/t4737 +test/files/pos/t5644 +test/files/pos/t5703 +test/files/run/inner-parse +test/files/run/t1430 +test/files/run/t2296a +test/files/run/t2296b +test/files/run/t3452a +test/files/run/t3452b +test/files/run/t3897 +test/files/run/t4119 +test/files/run/t4238 +test/files/run/t4317 +test/files/run/t4891 diff --git a/tools/compare-java-sigs b/tools/compare-java-sigs new file mode 100644 index 000000000000..99ab775437e8 --- /dev/null +++ b/tools/compare-java-sigs @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Compare javac -Xprint (i.e. see signatures from java point of view) +# for the given classes. +# +# Sample: +# +# % SCALA_HOME=/scala/inst/29 SCALA_BUILD=/scala/inst/3 tools/compare-java-sigs 'scala.Predef$' +# +# Comparing javac -Xprint for scala.Predef$ based on '/scala/inst/29' and '/scala/inst/3' +# 3c3 +# < public final class Predef$ extends scala.LowPriorityImplicits implements scala.ScalaObject { +# --- +# > public final class Predef$ extends scala.LowPriorityImplicits { +# 7d6 +# < private final scala.SpecializableCompanion AnyRef; +# 21,22d19 +# < public scala.SpecializableCompanion AnyRef(); +# < +# 68a66,67 +# > public scala.runtime.Nothing$ $qmark$qmark$qmark(); +# > +# 225c224,226 +# < public scala.collection.immutable.StringOps augmentString(java.lang.String x); +# --- +# > public scala.runtime.StringFormat any2stringfmt(java.lang.Object x); +# > +# > public java.lang.String augmentString(java.lang.String x); +# 227c228 +# < public java.lang.String unaugmentString(scala.collection.immutable.StringOps x); +# --- +# > public java.lang.String unaugmentString(java.lang.String x); +# + +set -e + +[[ $# -gt 0 ]] || { + echo "Usage: $(basename $0) ..." + echo "" + echo "# Example usage" + echo "SCALA_HOME=/scala/inst/29 SCALA_BUILD=/scala/inst/3 \\" + echo " $(basename $0) scala.Function1 scala.runtime.AbstractFunction1" + exit 0 +} + +home1=$(cd ${SCALA_HOME:-/scala/inst/3} && pwd) +home2=$(cd ${SCALA_BUILD:-$(dirname $BASH_SOURCE)/../build/pack} && pwd) + +echo "Comparing javac -Xprint for $@ based on '$home1' and '$home2'" +tmpdir=$(mktemp -dt $(basename $BASH_SOURCE)) + +cd $tmpdir +javac -Xprint -cp $home1:$home1/lib/'*' "$@" > before.txt +javac -Xprint -cp $home2:$home2/lib/'*' "$@" > after.txt + +diff before.txt after.txt && echo "No differences in javac -Xprint output."