From 8acd585a0c3b1dd4164ed76a7392471bb421589b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Bra=C4=8Devac?= Date: Wed, 23 Jul 2025 19:55:18 +0200 Subject: [PATCH] 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. --- compiler/src/dotty/tools/dotc/transform/Erasure.scala | 9 +++++++-- tests/run/i23179.scala | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/run/i23179.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index c743e757b8b4..cef21af23683 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -483,8 +483,13 @@ object Erasure { def sameClass(tp1: Type, tp2: Type) = tp1.classSymbol == tp2.classSymbol val paramAdaptationNeeded = - implParamTypes.lazyZip(samParamTypes).exists((implType, samType) => - !sameClass(implType, samType) && !autoAdaptedParam(implType)) + implParamTypes.lazyZip(samParamTypes).exists: (implType, samType) => + !sameClass(implType, samType) && !autoAdaptedParam(implType) + || (samType, implType).match { + case (defn.ArrayOf(_), defn.ArrayOf(_)) => false + case (defn.ArrayOf(_), _) => true // see #23179 + case _ => false + } val resultAdaptationNeeded = !sameClass(implResultType, samResultType) && !autoAdaptedResult diff --git a/tests/run/i23179.scala b/tests/run/i23179.scala new file mode 100644 index 000000000000..4085e56a03ea --- /dev/null +++ b/tests/run/i23179.scala @@ -0,0 +1,8 @@ +object Test { + trait A { def f(a: Array[AnyRef]): Any } + def g(a: A) = a.f(Array.empty[AnyRef]) + + def main(args: Array[String]): Unit = { + g((x: Array[? >: AnyRef]) => x.headOption) + } +}