diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-03-05 13:59:07 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-03-05 17:11:37 +1000 |
commit | 5471f011f85fef82cbe8bebb0c5f91b980031c5f (patch) | |
tree | a7b0cc30870eeb3ef2ecf8086f87a4a63fd8f39a | |
parent | d30098c30de94e6ec07b5c8b6782357183e24179 (diff) | |
download | scala-5471f011f85fef82cbe8bebb0c5f91b980031c5f.tar.gz scala-5471f011f85fef82cbe8bebb0c5f91b980031c5f.tar.bz2 scala-5471f011f85fef82cbe8bebb0c5f91b980031c5f.zip |
SI-9200 Fix Java generic signatures for refined types
The erasure of a refined type `T1 with T2 ... Tn` is the
erasure of the intersection dominator of the elements.
In addition to erased method signatures, the compiler also emits
Java generic signatures, included information about generic types,
up to the point that it is possible to express in the language of
Java 5 generics.
Java generic signatures must be consistent with erasued signatures,
that is, the Java compiler must erase that generic signature to the
same erased signature. If this does not hold, linkage errors will
occur.
The compiler implements erasure in `ErasureMap` and java generic
signatures in `Erasure#javaSig`. Regrettably, these don't share
any implementation; e.g `javaSig` only takes the first parent of
a refinement type, rather than using `intersectionDominator`.
This commit fixes that discrepency.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 4 | ||||
-rw-r--r-- | test/files/run/t9200/Test.java | 6 | ||||
-rw-r--r-- | test/files/run/t9200/test.scala | 12 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 5c72bb3258..f686df60fd 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -339,8 +339,8 @@ abstract class Erasure extends AddInterfaces buf append (if (restpe.typeSymbol == UnitClass || sym0.isConstructor) VOID_TAG.toString else jsig(restpe)) buf.toString - case RefinedType(parent :: _, decls) => - boxedSig(parent) + case RefinedType(parents, decls) => + boxedSig(intersectionDominator(parents)) case ClassInfoType(parents, _, _) => superSig(parents) case AnnotatedType(_, atp) => diff --git a/test/files/run/t9200/Test.java b/test/files/run/t9200/Test.java new file mode 100644 index 0000000000..8ff0314f6c --- /dev/null +++ b/test/files/run/t9200/Test.java @@ -0,0 +1,6 @@ +public class Test { + public static void main(String[] args) { + new C1(new C2()); // Was NoSuchMethodError + } +} + diff --git a/test/files/run/t9200/test.scala b/test/files/run/t9200/test.scala new file mode 100644 index 0000000000..6fa7e91571 --- /dev/null +++ b/test/files/run/t9200/test.scala @@ -0,0 +1,12 @@ +trait W + +trait T1 +trait T2 extends T1 + +object O1 { + type t = T1 with T2 +} + +class C1[w<:W](o: O1.t) + +class C2 extends T1 with T2 |