-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix bytecode generation for Single Abstract Method lambdas #11839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
42 | ||
Foo | ||
Foo |
This file contains hidden or 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,31 @@ | ||
sealed trait Partial | ||
sealed trait Total extends Partial | ||
|
||
case object Foo extends Total | ||
|
||
trait P[A] { | ||
def bar(a: A): Partial | ||
} | ||
|
||
trait T[A] extends P[A] { | ||
def bar(a: A): Total | ||
} | ||
|
||
object T { | ||
def make[A](x: Total): T[A] = | ||
a => x | ||
} | ||
|
||
object Test { | ||
def total[A](a: A)(ev: T[A]): Total = ev.bar(a) | ||
def partial[A](a: A)(ev: P[A]): Partial = ev.bar(a) | ||
|
||
def go[A](a: A)(ev: T[A]): Unit = { | ||
println(a) | ||
println(total(a)(ev)) | ||
println(partial(a)(ev)) | ||
} | ||
|
||
def main(args: Array[String]): Unit = | ||
go(42)(T.make(Foo)) | ||
} |
This file contains hidden or 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,23 @@ | ||
trait Foo[A] { | ||
def xxx(a1: A, a2: A): A | ||
def xxx(a: A): A = xxx(a, a) | ||
} | ||
|
||
trait Bar[A] extends Foo[A] { | ||
def yyy(a1: A, a2: A) = xxx(a1, a2) | ||
} | ||
|
||
trait Baz[A] extends Bar[A] | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = | ||
val foo: Foo[String] = { (s1, s2) => s1 ++ s2 } | ||
val bar: Bar[String] = { (s1, s2) => s1 ++ s2 } | ||
val baz: Baz[String] = { (s1, s2) => s1 ++ s2 } | ||
|
||
val s = "abc" | ||
val ss = "abcabc" | ||
assert(foo.xxx(s) == ss) | ||
assert(bar.yyy(s, s) == ss) | ||
assert(baz.xxx(s) == ss) | ||
assert(baz.yyy(s, s) == ss) |
This file contains hidden or 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,45 @@ | ||
// Taken from: https://github.com/scala/scala/pull/6087 | ||
|
||
trait JsonValue | ||
class JsonObject extends JsonValue | ||
class JsonString extends JsonValue | ||
|
||
trait JsonEncoder[A] { | ||
def encode(value: A): JsonValue | ||
} | ||
|
||
trait JsonObjectEncoder[A] extends JsonEncoder[A] { | ||
def encode(value: A): JsonObject | ||
} | ||
|
||
object JsonEncoderInstances { | ||
|
||
val seWorks: JsonEncoder[String] = | ||
new JsonEncoder[String] { | ||
def encode(value: String) = new JsonString | ||
} | ||
|
||
implicit val stringEncoder: JsonEncoder[String] = | ||
s => new JsonString | ||
//new JsonEncoder[String] { | ||
// def encode(value: String) = new JsonString | ||
//} | ||
|
||
def leWorks[A](implicit encoder: JsonEncoder[A]): JsonObjectEncoder[List[A]] = | ||
new JsonObjectEncoder[List[A]] { | ||
def encode(value: List[A]) = new JsonObject | ||
} | ||
|
||
implicit def listEncoder[A](implicit encoder: JsonEncoder[A]): JsonObjectEncoder[List[A]] = | ||
l => new JsonObject | ||
// new JsonObjectEncoder[List[A]] { | ||
// def encode(value: List[A]) = new JsonObject | ||
// } | ||
|
||
} | ||
|
||
object Test extends App { | ||
import JsonEncoderInstances._ | ||
|
||
implicitly[JsonEncoder[List[String]]].encode("" :: Nil) | ||
} |
This file contains hidden or 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,56 @@ | ||
// Taken from: https://github.com/scala/scala/pull/6087 | ||
|
||
trait A | ||
trait B extends A | ||
trait C extends B | ||
object it extends C | ||
|
||
/* try as many weird diamondy things as I can think of */ | ||
trait SAM_A { def apply(): A } | ||
trait SAM_A1 extends SAM_A { def apply(): A } | ||
trait SAM_B extends SAM_A1 { def apply(): B } | ||
trait SAM_B1 extends SAM_A1 { def apply(): B } | ||
trait SAM_B2 extends SAM_B with SAM_B1 | ||
trait SAM_C extends SAM_B2 { def apply(): C } | ||
|
||
trait SAM_F extends (() => A) with SAM_C | ||
trait SAM_F1 extends (() => C) with SAM_F | ||
|
||
|
||
object Test extends App { | ||
|
||
val s1: SAM_A = () => it | ||
val s2: SAM_A1 = () => it | ||
val s3: SAM_B = () => it | ||
val s4: SAM_B1 = () => it | ||
val s5: SAM_B2 = () => it | ||
val s6: SAM_C = () => it | ||
val s7: SAM_F = () => it | ||
val s8: SAM_F1 = () => it | ||
|
||
(s1(): A) | ||
|
||
(s2(): A) | ||
|
||
(s3(): B) | ||
(s3(): A) | ||
|
||
(s4(): B) | ||
(s4(): A) | ||
|
||
(s5(): B) | ||
(s5(): A) | ||
|
||
(s6(): C) | ||
(s6(): B) | ||
(s6(): A) | ||
|
||
(s7(): C) | ||
(s7(): B) | ||
(s7(): A) | ||
|
||
(s8(): C) | ||
(s8(): B) | ||
(s8(): A) | ||
|
||
} |
This file contains hidden or 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,25 @@ | ||
sealed trait PartialOrdering | ||
sealed trait Ordering extends PartialOrdering | ||
|
||
object Ordering { | ||
def fromCompare(n: Int): Ordering = new Ordering {} | ||
} | ||
|
||
trait PartialOrd[-A] { | ||
def checkCompare(l: A, r: A): PartialOrdering | ||
} | ||
|
||
trait Ord[-A] extends PartialOrd[A] { | ||
def checkCompare(l: A, r: A): Ordering | ||
} | ||
|
||
object Ord { | ||
def fromScala[A](implicit ordering: scala.math.Ordering[A]): Ord[A] = | ||
(l: A, r: A) => Ordering.fromCompare(ordering.compare(l, r)) | ||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = | ||
val intOrd = Ord.fromScala[Int] | ||
intOrd.checkCompare(1, 3) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding the same comment than in Scala 2 for context: