Skip to content

Commit 10bc131

Browse files
committed
Ensure Array[? >: AnyRef] erases to Object[]
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 now align with Scala 2's behavior and erase `Array[? >: AnyRef]` to `Object[]` instead of just `Object`. This seems consistent with how we handle `Array[Any]`, which also erases to `Object[]`.
1 parent 570e840 commit 10bc131

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ object TypeErasure {
361361
isGenericArrayElement(tp.alias, isScala2)
362362
case tp: TypeBounds =>
363363
!fitsInJVMArray(tp.hi)
364+
&& !(tp.lo.isAnyRef && tp.hi.isAny) // #23179, aligns with Scala 2 behavior for Array[? >: AnyRef]
364365
case tp: MatchType =>
365366
val alts = tp.alternatives
366367
alts.nonEmpty && !fitsInJVMArray(alts.reduce(OrType(_, _, soft = true)))

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)