diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-05-05 09:59:43 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-05-05 10:04:49 +1000 |
commit | a18e42bc0773084a3e311646e1e2ffd623db4cfa (patch) | |
tree | c06957d9199e507144ddff039edb2c82bae44dd3 | |
parent | f635ba91d641d900ffd56ae0f4bbfb8e88bfe2d1 (diff) | |
download | scala-a18e42bc0773084a3e311646e1e2ffd623db4cfa.tar.gz scala-a18e42bc0773084a3e311646e1e2ffd623db4cfa.tar.bz2 scala-a18e42bc0773084a3e311646e1e2ffd623db4cfa.zip |
SI-9298 Fix erasure of value classes in Java
Value classes that appear in signatures of Java defined methods
should not be erased to the underlying type.
Before this change, we'd get a `ClassCastException`, as the Scala
call site would unbox the value class despite the fact the Java
recipient would expect the boxed representation.
I've tested this for primitive and object wrapped types in parameter
and return position.
-rw-r--r-- | src/reflect/scala/reflect/internal/transform/Erasure.scala | 2 | ||||
-rw-r--r-- | test/files/run/t9298/Test.java | 7 | ||||
-rw-r--r-- | test/files/run/t9298/VC.scala | 5 | ||||
-rw-r--r-- | test/files/run/t9298b/Test.java | 7 | ||||
-rw-r--r-- | test/files/run/t9298b/VC.scala | 8 |
5 files changed, 29 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/transform/Erasure.scala b/src/reflect/scala/reflect/internal/transform/Erasure.scala index d5b5967145..707972242a 100644 --- a/src/reflect/scala/reflect/internal/transform/Erasure.scala +++ b/src/reflect/scala/reflect/internal/transform/Erasure.scala @@ -254,6 +254,8 @@ trait Erasure { def mergeParents(parents: List[Type]): Type = if (parents.isEmpty) ObjectTpe else parents.head + + override protected def eraseDerivedValueClassRef(tref: TypeRef): Type = eraseNormalClassRef(tref) } object scalaErasure extends ScalaErasureMap diff --git a/test/files/run/t9298/Test.java b/test/files/run/t9298/Test.java new file mode 100644 index 0000000000..81f5265985 --- /dev/null +++ b/test/files/run/t9298/Test.java @@ -0,0 +1,7 @@ +public class Test { + public void consume(VC vc) {} + + public static void main(String[] args) { + new Client().test(); + } +} diff --git a/test/files/run/t9298/VC.scala b/test/files/run/t9298/VC.scala new file mode 100644 index 0000000000..916e62dc59 --- /dev/null +++ b/test/files/run/t9298/VC.scala @@ -0,0 +1,5 @@ +class VC(val s: String) extends AnyVal + +class Client { + def test = new Test().consume(new VC("")) +} diff --git a/test/files/run/t9298b/Test.java b/test/files/run/t9298b/Test.java new file mode 100644 index 0000000000..f369b26f36 --- /dev/null +++ b/test/files/run/t9298b/Test.java @@ -0,0 +1,7 @@ +public class Test { + public VC identity(VC vc) { return vc; } + + public static void main(String[] args) { + new Client().test(); + } +} diff --git a/test/files/run/t9298b/VC.scala b/test/files/run/t9298b/VC.scala new file mode 100644 index 0000000000..bb5978b6e4 --- /dev/null +++ b/test/files/run/t9298b/VC.scala @@ -0,0 +1,8 @@ +class VC(val s: Int) extends AnyVal + +class Client { + def test = { + val vc: VC = new Test().identity(new VC(42)) + assert(vc.s == 42) + } +} |