File tree 3 files changed +9
-10
lines changed
3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -1459,8 +1459,10 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
1459
1459
1460
1460
val methodName = samMethod.javaSimpleName
1461
1461
val samMethodType = asmMethodType(samMethod).toASMType
1462
+ // scala/bug#10334: make sure that a lambda object for `T => U` has a method `apply(T)U`, not only the `(Object)Object`
1463
+ // version. Using the lambda a structural type `{def apply(t: T): U}` causes a reflective lookup for this method.
1462
1464
val needsGenericBridge = samMethodType != instantiatedMethodType
1463
- val bridgeMethods = atPhase(erasurePhase.prev ){
1465
+ val bridgeMethods = atPhase(erasurePhase){
1464
1466
samMethod.allOverriddenSymbols.toList
1465
1467
}
1466
1468
val overriddenMethodTypes = bridgeMethods.map(b => asmMethodType(b).toASMType)
Original file line number Diff line number Diff line change @@ -927,10 +927,10 @@ object Types {
927
927
*/
928
928
final def possibleSamMethods (using Context ): Seq [SingleDenotation ] = {
929
929
record(" possibleSamMethods" )
930
- atPhaseNoLater(erasurePhase.prev ) {
930
+ atPhaseNoLater(erasurePhase) {
931
931
abstractTermMembers.toList.filterConserve(m =>
932
932
! m.symbol.matchingMember(defn.ObjectType ).exists && ! m.symbol.isSuperAccessor)
933
- }
933
+ }.map(_.current)
934
934
}
935
935
936
936
/** The set of abstract type members of this type. */
Original file line number Diff line number Diff line change @@ -433,12 +433,9 @@ object Erasure {
433
433
val implReturnsUnit = implResultType.classSymbol eq defn.UnitClass
434
434
// The SAM that this closure should implement.
435
435
// At this point it should be already guaranteed that there's only one method to implement
436
- val Seq (unerasedSam) = lambdaType.possibleSamMethods
437
- // We're now in erasure so the alternatives will have erased types
438
- val Seq (erasedSam : MethodType ) = unerasedSam.symbol.alternatives.map(_.info)
439
-
440
- val samParamTypes = erasedSam.paramInfos
441
- val samResultType = erasedSam.resultType
436
+ val Seq (sam : MethodType ) = lambdaType.possibleSamMethods.map(_.info)
437
+ val samParamTypes = sam.paramInfos
438
+ val samResultType = sam.resultType
442
439
443
440
/** Can the implementation parameter type `tp` be auto-adapted to a different
444
441
* parameter type in the SAM?
@@ -502,7 +499,7 @@ object Erasure {
502
499
val bridgeType =
503
500
if paramAdaptationNeeded then
504
501
if resultAdaptationNeeded then
505
- erasedSam
502
+ sam
506
503
else
507
504
implType.derivedLambdaType(paramInfos = samParamTypes)
508
505
else
You can’t perform that action at this time.
0 commit comments