diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 70eebc750521..acb27adde7fc 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1030,13 +1030,13 @@ class Definitions { /** An extractor for multi-dimensional arrays. * Note that this will also extract the high bound if an - * element type is a wildcard. E.g. + * element type is a wildcard upper-bounded by an array. E.g. * * Array[? <: Array[? <: Number]] * * would match * - * MultiArrayOf(, 2) + * MultiArrayOf(, 2) */ object MultiArrayOf { def apply(elem: Type, ndims: Int)(using Context): Type = @@ -1044,7 +1044,8 @@ class Definitions { def unapply(tp: Type)(using Context): Option[(Type, Int)] = tp match { case ArrayOf(elemtp) => def recur(elemtp: Type): Option[(Type, Int)] = elemtp.dealias match { - case TypeBounds(lo, hi) => recur(hi) + case tp @ TypeBounds(lo, hi @ MultiArrayOf(finalElemTp, n)) => + Some(finalElemTp, n) case MultiArrayOf(finalElemTp, n) => Some(finalElemTp, n + 1) case _ => Some(elemtp, 1) } diff --git a/tests/run/array-erasure.scala b/tests/run/array-erasure.scala index 264fe46c36e5..1ce727337a4f 100644 --- a/tests/run/array-erasure.scala +++ b/tests/run/array-erasure.scala @@ -65,5 +65,11 @@ object Test { arr4(x) arr5(x) arr6(x) + + + val str: Any = "" + assert(!str.isInstanceOf[Array[?]]) + assert(!str.isInstanceOf[Array[Array[?]]]) + assert(!str.isInstanceOf[Array[? <: Array[?]]]) } }