From 33e71061d63d08ee23e28d9a43ad601afa74e043 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Tue, 5 Apr 2016 22:01:43 +0200 Subject: SD-98 don't emit unnecessary mixin forwarders In most cases when a class inherits a concrete method from a trait we don't need to generate a forwarder to the default method in the class. t5148 is moved to pos as it compiles without error now. the error message ("missing or invalid dependency") is still tested by t6440b. --- test/files/neg/t4749.check | 2 +- test/files/neg/t5148.check | 16 ---------------- test/files/neg/t5148.scala | 4 ---- test/files/pos/t5148.scala | 4 ++++ test/files/run/mixin-signatures.check | 21 ++++++++++++++------- test/files/run/t5652.check | 1 - test/files/run/t6554.scala | 12 +++++++++--- test/files/run/t7932.check | 5 ++++- test/files/run/t7932.scala | 25 +++++++++++++++++++++---- 9 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 test/files/neg/t5148.check delete mode 100644 test/files/neg/t5148.scala create mode 100644 test/files/pos/t5148.scala (limited to 'test/files') diff --git a/test/files/neg/t4749.check b/test/files/neg/t4749.check index 3539140954..6bd2550097 100644 --- a/test/files/neg/t4749.check +++ b/test/files/neg/t4749.check @@ -26,7 +26,7 @@ t4749.scala:26: warning: Fail6 has a main method with parameter type Array[Strin object Fail6 { ^ t4749.scala:42: warning: Win3 has a main method with parameter type Array[String], but bippy.Win3 will not be a runnable program. - Reason: main method must have exact signature (Array[String])Unit + Reason: main methods cannot refer to type parameters or abstract types. object Win3 extends WinBippy[Unit] { } ^ error: No warnings can be incurred under -Xfatal-warnings. diff --git a/test/files/neg/t5148.check b/test/files/neg/t5148.check deleted file mode 100644 index 1f58c235ce..0000000000 --- a/test/files/neg/t5148.check +++ /dev/null @@ -1,16 +0,0 @@ -error: missing or invalid dependency detected while loading class file 'Imports.class'. -Could not access term memberHandlers in class scala.tools.nsc.interpreter.IMain, -because it (or its dependencies) are missing. Check your build definition for -missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) -A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain. -error: missing or invalid dependency detected while loading class file 'Imports.class'. -Could not access type Wrapper in class scala.tools.nsc.interpreter.IMain.Request, -because it (or its dependencies) are missing. Check your build definition for -missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) -A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain.Request. -error: missing or invalid dependency detected while loading class file 'Imports.class'. -Could not access type Request in class scala.tools.nsc.interpreter.IMain, -because it (or its dependencies) are missing. Check your build definition for -missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) -A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain. -three errors found diff --git a/test/files/neg/t5148.scala b/test/files/neg/t5148.scala deleted file mode 100644 index fca64e57df..0000000000 --- a/test/files/neg/t5148.scala +++ /dev/null @@ -1,4 +0,0 @@ -package scala.tools.nsc -package interpreter - -class IMain extends Imports diff --git a/test/files/pos/t5148.scala b/test/files/pos/t5148.scala new file mode 100644 index 0000000000..fca64e57df --- /dev/null +++ b/test/files/pos/t5148.scala @@ -0,0 +1,4 @@ +package scala.tools.nsc +package interpreter + +class IMain extends Imports diff --git a/test/files/run/mixin-signatures.check b/test/files/run/mixin-signatures.check index 77bff79ac8..9961992e2d 100644 --- a/test/files/run/mixin-signatures.check +++ b/test/files/run/mixin-signatures.check @@ -1,19 +1,23 @@ class Test$bar1$ { - public java.lang.String Test$bar1$.f(java.lang.Object) + public default java.lang.String Foo1.f(java.lang.Object) + generic: public default java.lang.String Foo1.f(T) 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) + public default java.lang.Object Base.h(java.lang.Object) + generic: public default R Base.h(T) } class Test$bar2$ { - public java.lang.Object Test$bar2$.f(java.lang.String) + public default java.lang.Object Foo2.f(java.lang.String) + generic: public default R Foo2.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) + public default java.lang.Object Base.h(java.lang.Object) + generic: public default R Base.h(T) } class Test$bar3$ { @@ -23,7 +27,8 @@ class Test$bar3$ { 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) + public default java.lang.Object Base.h(java.lang.Object) + generic: public default R Base.h(T) } class Test$bar4$ { @@ -33,7 +38,8 @@ class Test$bar4$ { 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) + public default java.lang.Object Base.h(java.lang.Object) + generic: public default R Base.h(T) } class Test$bar5$ { @@ -45,7 +51,8 @@ class Test$bar5$ { public java.lang.Object Test$bar5$.g(java.lang.Object) public java.lang.Object Test$bar5$.g(java.lang.String) public java.lang.String Test$bar5$.g(java.lang.Object) - public java.lang.Object Test$bar5$.h(java.lang.Object) + public default java.lang.Object Base.h(java.lang.Object) + generic: public default R Base.h(T) } interface Foo1 { diff --git a/test/files/run/t5652.check b/test/files/run/t5652.check index 326b22f9dd..a0fb6fe9b4 100644 --- a/test/files/run/t5652.check +++ b/test/files/run/t5652.check @@ -4,5 +4,4 @@ public default void T1.$init$() public final int A1.A1$$g$2() public int A1.f1() public final int A2.A2$$g$1() -public int A2.f0() public int A2.f2() diff --git a/test/files/run/t6554.scala b/test/files/run/t6554.scala index 5d29d16666..eed139fea6 100644 --- a/test/files/run/t6554.scala +++ b/test/files/run/t6554.scala @@ -1,8 +1,14 @@ -trait Foo[A] { +trait T1[A] { def minBy[B](b: B): A = ??? } - -class Bar extends Foo[Int] + +// The second trait is needed to make sure there's a forwarder generated in Bar. +// otherwise Bar.minBy is just the inherited default method from T1. +trait T2[A] { self: T1[A] => + override def minBy[B](b: B): A = ??? +} + +class Bar extends T1[Int] with T2[Int] object Test extends App { val sigs = classOf[Bar].getDeclaredMethods.map(m => s"${m.toString} / ${m.toGenericString}").sorted diff --git a/test/files/run/t7932.check b/test/files/run/t7932.check index 3f0a0c4f62..a2ad84cd46 100644 --- a/test/files/run/t7932.check +++ b/test/files/run/t7932.check @@ -1,3 +1,6 @@ -warning: there was one feature warning; re-run with -feature for details public Category C.category() public Category C.category1() +public default Category M1.category() +public default Category M1.category1() +public default Category M2.category() +public default Category M2.category1() diff --git a/test/files/run/t7932.scala b/test/files/run/t7932.scala index 8743abff88..e6bdbf2417 100644 --- a/test/files/run/t7932.scala +++ b/test/files/run/t7932.scala @@ -1,11 +1,28 @@ +import scala.language.higherKinds + class Category[M[_, _]] -trait M[F] { + +trait M1[F] { type X[a, b] = F def category: Category[X] = null def category1: Category[Tuple2] = null } -abstract class C extends M[Float] + +// The second trait is needed to make sure there's a forwarder generated in C. +// otherwise the trait methods are just the inherited default methods from M1. +trait M2[F] { self: M1[F] => + override def category: Category[X] = null + override def category1: Category[Tuple2] = null +} + +abstract class C extends M1[Float] with M2[Float] + object Test extends App { - val ms = classOf[C].getMethods.filter(_.getName.startsWith("category")) - println(ms.map(_.toGenericString).sorted.mkString("\n")) + def t(c: Class[_]) = { + val ms = c.getMethods.filter(_.getName.startsWith("category")) + println(ms.map(_.toGenericString).sorted.mkString("\n")) + } + t(classOf[C]) + t(classOf[M1[_]]) + t(classOf[M2[_]]) } -- cgit v1.2.3