File tree 2 files changed +10
-3
lines changed
compiler/src/dotty/tools/dotc/core
2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -1031,21 +1031,22 @@ class Definitions {
1031
1031
1032
1032
/** An extractor for multi-dimensional arrays.
1033
1033
* Note that this will also extract the high bound if an
1034
- * element type is a wildcard. E.g.
1034
+ * element type is a wildcard upper-bounded by an array . E.g.
1035
1035
*
1036
1036
* Array[? <: Array[? <: Number]]
1037
1037
*
1038
1038
* would match
1039
1039
*
1040
- * MultiArrayOf(<Number>, 2)
1040
+ * MultiArrayOf(<? <: Number>, 2)
1041
1041
*/
1042
1042
object MultiArrayOf {
1043
1043
def apply (elem : Type , ndims : Int )(using Context ): Type =
1044
1044
if (ndims == 0 ) elem else ArrayOf (apply(elem, ndims - 1 ))
1045
1045
def unapply (tp : Type )(using Context ): Option [(Type , Int )] = tp match {
1046
1046
case ArrayOf (elemtp) =>
1047
1047
def recur (elemtp : Type ): Option [(Type , Int )] = elemtp.dealias match {
1048
- case TypeBounds (lo, hi) => recur(hi)
1048
+ case tp @ TypeBounds (lo, hi @ MultiArrayOf (finalElemTp, n)) =>
1049
+ Some (finalElemTp, n)
1049
1050
case MultiArrayOf (finalElemTp, n) => Some (finalElemTp, n + 1 )
1050
1051
case _ => Some (elemtp, 1 )
1051
1052
}
Original file line number Diff line number Diff line change @@ -65,5 +65,11 @@ object Test {
65
65
arr4(x)
66
66
arr5(x)
67
67
arr6(x)
68
+
69
+
70
+ val str : Any = " "
71
+ assert(! str.isInstanceOf [Array [? ]])
72
+ assert(! str.isInstanceOf [Array [Array [? ]]])
73
+ assert(! str.isInstanceOf [Array [? <: Array [? ]]])
68
74
}
69
75
}
You can’t perform that action at this time.
0 commit comments