Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 8200009

Browse files
committed
Merge pull request scala#4490 from retronym/ticket/9298
SI-9298 Fix erasure of value classes in Java
2 parents f635ba9 + a18e42b commit 8200009

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/reflect/scala/reflect/internal/transform/Erasure.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ trait Erasure {
254254
def mergeParents(parents: List[Type]): Type =
255255
if (parents.isEmpty) ObjectTpe
256256
else parents.head
257+
258+
override protected def eraseDerivedValueClassRef(tref: TypeRef): Type = eraseNormalClassRef(tref)
257259
}
258260

259261
object scalaErasure extends ScalaErasureMap

test/files/run/t9298/Test.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Test {
2+
public void consume(VC vc) {}
3+
4+
public static void main(String[] args) {
5+
new Client().test();
6+
}
7+
}

test/files/run/t9298/VC.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class VC(val s: String) extends AnyVal
2+
3+
class Client {
4+
def test = new Test().consume(new VC(""))
5+
}

test/files/run/t9298b/Test.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Test {
2+
public VC identity(VC vc) { return vc; }
3+
4+
public static void main(String[] args) {
5+
new Client().test();
6+
}
7+
}

test/files/run/t9298b/VC.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class VC(val s: Int) extends AnyVal
2+
3+
class Client {
4+
def test = {
5+
val vc: VC = new Test().identity(new VC(42))
6+
assert(vc.s == 42)
7+
}
8+
}

0 commit comments

Comments
 (0)