|
The delambdafy creates a bridge method which requires adaptation
of the result type to the generic `Object`, which is the erased
return type of FunctionN.
This bridge building reused some code from erasure, now refactored
into TypeAdaptingTransformer.
But, it was running into problems with:
class C(a: Int) extends AnyVal
(x: Any) => new C(0)
It created (forgive the pseudo quasiquote syntax):
class anonfun$ extends Function1[Any, C] {
def apply#1(a: Object): Int = 0
<bridge> def apply#2(a: Object): Object = {
val result: Int = apply#1(a)
${adapt(Ident("result"), ObjectType)}
}
}
This resulted in primitive boxing, rather than value class boxing.
Instead, we need the call to the main apply method to be typed
as `ErasedValueClass(C, Int)`, which `adapt` takes as a trigger
to perform value class boxing.
Finally, we have to run the post-erasure transformer over the adapted
tree to eliminate remnants of `ErasedValueClass` from the types of
trees.
|