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 @@ -1029,21 +1029,22 @@ class Definitions {
1029
1029
1030
1030
/** An extractor for multi-dimensional arrays.
1031
1031
* Note that this will also extract the high bound if an
1032
- * element type is a wildcard. E.g.
1032
+ * element type is a wildcard upper-bounded by an array . E.g.
1033
1033
*
1034
1034
* Array[? <: Array[? <: Number]]
1035
1035
*
1036
1036
* would match
1037
1037
*
1038
- * MultiArrayOf(<Number>, 2)
1038
+ * MultiArrayOf(<? <: Number>, 2)
1039
1039
*/
1040
1040
object MultiArrayOf {
1041
1041
def apply (elem : Type , ndims : Int )(using Context ): Type =
1042
1042
if (ndims == 0 ) elem else ArrayOf (apply(elem, ndims - 1 ))
1043
1043
def unapply (tp : Type )(using Context ): Option [(Type , Int )] = tp match {
1044
1044
case ArrayOf (elemtp) =>
1045
1045
def recur (elemtp : Type ): Option [(Type , Int )] = elemtp.dealias match {
1046
- case TypeBounds (lo, hi) => recur(hi)
1046
+ case tp @ TypeBounds (lo, hi @ MultiArrayOf (finalElemTp, n)) =>
1047
+ Some (finalElemTp, n)
1047
1048
case MultiArrayOf (finalElemTp, n) => Some (finalElemTp, n + 1 )
1048
1049
case _ => Some (elemtp, 1 )
1049
1050
}
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