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.
Associative, commutative, Java-friendly intersection erasure
Thanks to scala#11603, we can now freely decide how we erase our intersection types without compromising compatibility with Scala 2. We take advantage of this by designing a new erasedGlb algorithm which respects associativity and commutativity and can also erase Java intersections without any special case. This commit also improves the way we handle intersections in Java generic signature to produce more precise types when possible and to ensure that we never emit a type that would lead to javac emitting invalid bytecode (which can happen with Scala 2: scala/bug#12300).
- Loading branch information
Showing
10 changed files
with
223 additions
and
59 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
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,5 @@ | ||
trait A { def foo(a: A) : Unit } | ||
|
||
trait C extends A { | ||
override def foo(a: A with Any): Unit // error: method foo has a different signature than the overridden declaration | ||
} |
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
trait One | ||
trait Two | ||
|
||
class X | ||
class Y extends X | ||
|
||
trait YSub extends Y | ||
|
||
class A { | ||
def foo1[T <: Object with One](x: T): Unit = {} | ||
def foo2[T <: One with Object](x: T): Unit = {} | ||
def foo3[T <: One with Two](x: T): Unit = {} | ||
def foo4[T <: Two with One](x: T): Unit = {} | ||
def foo5[T <: X with Y](x: T): Unit = {} | ||
def foo6[T <: Y with X](x: T): Unit = {} | ||
def foo7[T <: X with YSub](x: T): Unit = {} | ||
def foo8[T <: YSub with X](x: T): Unit = {} | ||
} |
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,17 @@ | ||
class OneTwo implements One, Two {} | ||
// Java doesn't seen class parents of traits | ||
class YSubX extends Y implements YSub {} | ||
|
||
public class B_2 { | ||
public static void foo() { | ||
A a = new A(); | ||
a.foo1(new One() {}); | ||
a.foo2(new One() {}); | ||
a.foo3(new OneTwo()); | ||
a.foo4(new OneTwo()); | ||
a.foo5(new Y()); | ||
a.foo6(new Y()); | ||
a.foo7(new YSubX()); | ||
a.foo8(new YSubX()); | ||
} | ||
} |
Oops, something went wrong.