Expand lambdas to anonymous classes when LMF cannot implement them#11205
Expand lambdas to anonymous classes when LMF cannot implement them#11205lrytz merged 2 commits intoscala:2.13.xfrom
Conversation
LambdaMetaFactory can adapt / bridge when the parameter / result types
of a lambda don't exactly match up with the SAM, for example by
introducing a cast or boxing.
We use that functionality, but not in all cases; unboxing `null` in
Scala needs to produce zero, not an NPE. For that reason we manually
create an `anonfun$adapted` bridge in Delambdafy when necessary.
LMF can also generate a bridge methods if needed, for example:
```
trait F1[-T, +R] { def apply(t: T): R }
trait SF[-T] extends F1[T, Unit] { def apply(t: T): Unit }
```
LMF does the same adaptations when generating bridges. Here, in case
the adaptation by LMF doesn't match the semantics we need for Scala,
we have to bail out and emit an anonymous class. This is added in this
PR.
... written by an agent, of course (copilot / claude-sonnet-4.5), edited by me.
|
@SethTisue review of AGENTS.md? |
Seems pretty thorough to me, and might be useful to humans as well. We can always add things later. |
|
@noti0na1 could you review this? |
|
Sure! |
noti0na1
left a comment
There was a problem hiding this comment.
The changes look reasonable to me. Do we have issue about auto-adopting Array with Object in Scala 2?
|
BTW, does the |
Your test case I backported passes, so it seems OK. I think it's handled by
I just started using the robot recently, but yeah. At least it then knows how to build the project and run a test, since it's not just |
LambdaMetaFactory can adapt / bridge when the parameter / result types of a lambda don't exactly match up with the SAM, for example by introducing a cast or boxing.
We use that functionality, but not in all cases; unboxing
nullin Scala needs to produce zero, not an NPE. For that reason we manually create ananonfun$adaptedbridge in Delambdafy when necessary.LMF can also generate a bridge methods if needed, for example:
LMF does the same adaptations when generating bridges. Here, in case the adaptation by LMF doesn't match the semantics we need for Scala, we have to bail out and emit an anonymous class. This is added in this PR.
Backport of scala/scala3#24624
Fixes scala/bug#13142