forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix erasure of Java intersection without a class
When I implemented our erasure algorithm in scala#11808, I misread https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.4 and incorrectly thought that a Java intersection had to contain at least one class, and since we always erase a Scala 3 intersection containing a class to that class, I thought we could use the Scala 3 intersection algorithm to erase Java intersections. But my assumption was incorrect: a Java intersection can in fact contain only interfaces, so we need to special-case them in erasure like before. Fixes scala#12586.
- Loading branch information
Showing
6 changed files
with
46 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
1 | ||
2 | ||
1 | ||
Sub1 | ||
2 | ||
Sub2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import java.io.Serializable; | ||
|
||
public class A_1 { | ||
public <T extends Object & java.io.Serializable> void foo(T x) {} | ||
public <T extends Object & Serializable> void foo(T x) { | ||
System.out.println("1"); | ||
} | ||
|
||
public <T extends Cloneable & Serializable> void foo(T x) { | ||
System.out.println("2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
import java.io.Serializable | ||
|
||
class Sub extends A_1 { | ||
override def foo[T <: Object & Serializable](x: T) = | ||
super.foo(x) | ||
println("Sub1") | ||
|
||
override def foo[T <: Cloneable & Serializable](x: T) = | ||
super.foo(x) | ||
println("Sub2") | ||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val x: Object & Serializable = new Serializable {} | ||
val y: Cloneable & Serializable = new Cloneable with java.io.Serializable {} | ||
|
||
val a = new A_1 | ||
val x: java.io.Serializable = new java.io.Serializable {} | ||
a.foo(x) | ||
a.foo(y) | ||
|
||
val s = new Sub | ||
s.foo(x) | ||
s.foo(y) | ||
} | ||
} |