Skip to content

Commit 8acd585

Browse files
committed
Refine parameter adaptation logic for arrays
Fixes #23179 Since JDK 9, argument checks for LambdaMetaFactory have become stricter. Which is to say that its JDK 8 version was too lax. We apply adaptation now in case the samType is an array, but the implType is not.
1 parent 570e840 commit 8acd585

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,13 @@ object Erasure {
483483
def sameClass(tp1: Type, tp2: Type) = tp1.classSymbol == tp2.classSymbol
484484

485485
val paramAdaptationNeeded =
486-
implParamTypes.lazyZip(samParamTypes).exists((implType, samType) =>
487-
!sameClass(implType, samType) && !autoAdaptedParam(implType))
486+
implParamTypes.lazyZip(samParamTypes).exists: (implType, samType) =>
487+
!sameClass(implType, samType) && !autoAdaptedParam(implType)
488+
|| (samType, implType).match {
489+
case (defn.ArrayOf(_), defn.ArrayOf(_)) => false
490+
case (defn.ArrayOf(_), _) => true // see #23179
491+
case _ => false
492+
}
488493
val resultAdaptationNeeded =
489494
!sameClass(implResultType, samResultType) && !autoAdaptedResult
490495

tests/run/i23179.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
trait A { def f(a: Array[AnyRef]): Any }
3+
def g(a: A) = a.f(Array.empty[AnyRef])
4+
5+
def main(args: Array[String]): Unit = {
6+
g((x: Array[? >: AnyRef]) => x.headOption)
7+
}
8+
}

0 commit comments

Comments
 (0)