summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-04-09 16:53:21 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-04-09 16:53:21 -0700
commit3ce8417b9ab00963c3da342d03a45ed492d6b69b (patch)
tree8d681bc9208314d53e63e230fa2aafeb869ae3da
parent68e05701cd9ef633f7a22b82794c81f67d45be16 (diff)
parente9bfa33c1eef822eb9d3d0f471f4bbbe390e1e65 (diff)
downloadscala-3ce8417b9ab00963c3da342d03a45ed492d6b69b.tar.gz
scala-3ce8417b9ab00963c3da342d03a45ed492d6b69b.tar.bz2
scala-3ce8417b9ab00963c3da342d03a45ed492d6b69b.zip
Merge pull request #4403 from gourlaysama/wip/t9239-generic-signature
SI-9239 fix java generic signature when traits extend classes
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala10
-rw-r--r--test/files/pos/t9239/Declaration.scala3
-rw-r--r--test/files/pos/t9239/Usage.java15
3 files changed, 24 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index facce9062b..9fdc3a9d72 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -188,14 +188,16 @@ abstract class Erasure extends AddInterfaces
/* Drop redundant types (ones which are implemented by some other parent) from the immediate parents.
* This is important on Android because there is otherwise an interface explosion.
*/
- def minimizeParents(parents: List[Type]): List[Type] = {
- var rest = parents
- var leaves = collection.mutable.ListBuffer.empty[Type]
+ def minimizeParents(parents: List[Type]): List[Type] = if (parents.isEmpty) parents else {
+ def isInterfaceOrTrait(sym: Symbol) = sym.isInterface || sym.isTrait
+
+ var rest = parents.tail
+ var leaves = collection.mutable.ListBuffer.empty[Type] += parents.head
while(rest.nonEmpty) {
val candidate = rest.head
val nonLeaf = leaves exists { t => t.typeSymbol isSubClass candidate.typeSymbol }
if(!nonLeaf) {
- leaves = leaves filterNot { t => candidate.typeSymbol isSubClass t.typeSymbol }
+ leaves = leaves filterNot { t => isInterfaceOrTrait(t.typeSymbol) && (candidate.typeSymbol isSubClass t.typeSymbol) }
leaves += candidate
}
rest = rest.tail
diff --git a/test/files/pos/t9239/Declaration.scala b/test/files/pos/t9239/Declaration.scala
new file mode 100644
index 0000000000..452dcc1e77
--- /dev/null
+++ b/test/files/pos/t9239/Declaration.scala
@@ -0,0 +1,3 @@
+class Foo[A]
+trait Bar[A] extends Foo[A]
+class Baz[A] extends Bar[A]
diff --git a/test/files/pos/t9239/Usage.java b/test/files/pos/t9239/Usage.java
new file mode 100644
index 0000000000..d1e3fb0c3e
--- /dev/null
+++ b/test/files/pos/t9239/Usage.java
@@ -0,0 +1,15 @@
+/**
+ * Used to fail with:
+ *
+ * Usage.java:5: error: incompatible types: Baz<String> cannot be converted to Foo<String>
+ * foo(f);
+ * ^
+ */
+public class Usage {
+ public Usage() {
+ Baz<String> f = null;
+ foo(f);
+ }
+
+ public void foo(Foo<String> f) { };
+}