From 0e14e70b1bb4b079990b952ada3e8dd6b8de955d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 8 Nov 2015 18:29:27 +0100 Subject: Generalize MultiArrayOf to arrays of wildcards Needed for both ClassTags and instance of checks. This makes scala/Array.scala compile. --- src/dotty/tools/dotc/core/Definitions.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/core/Definitions.scala') diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index b08a20889..433b8544a 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -529,15 +529,27 @@ 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. + * + * Array[_ <: Array[_ <: Number]] + * + * would match + * + * MultiArrayOf(, 2) + */ object MultiArrayOf { def apply(elem: Type, ndims: Int)(implicit ctx: Context): Type = if (ndims == 0) elem else ArrayOf(apply(elem, ndims - 1)) def unapply(tp: Type)(implicit ctx: Context): Option[(Type, Int)] = tp match { case ArrayOf(elemtp) => - elemtp match { + def recur(elemtp: Type): Option[(Type, Int)] = elemtp.dealias match { + case TypeBounds(lo, hi) => recur(hi) case MultiArrayOf(finalElemTp, n) => Some(finalElemTp, n + 1) case _ => Some(elemtp, 1) } + recur(elemtp) case _ => None } -- cgit v1.2.3