Commit 4a384e7
committed
Fix isInstanceOf[Array[?]] returning true on non-Array
Before this commit, the `MultiArrayOf(elem, ndims)` extractor used to
strip wildcards from the element type, this was surprising since it does
not match what the `ArrayOf(elem)` extractor does, and lead to a bug in
`TypeTestCasts.interceptTypeApply` which contains the following code:
case defn.MultiArrayOf(elem, ndims) if isGenericArrayElement(elem, isScala2 = false) =>
`isGenericArrayElement` returns false for `Any` but true for
`_ >: Nothing <: Any`, so the stripped wildcard means that this case was
skipped, resulting in:
x.isInstanceOf[Array[?]]
being erased to:
x.isInstanceOf[Object]
instead of:
scala.runtime.ScalaRunTime.isArray(x, 1)
Fixed by tweaking `MultiArrayOf` to keep any final wildcard around like
`ArrayOf` does.1 parent 6dbf28a commit 4a384e7
File tree
2 files changed
+10
-3
lines changed- compiler/src/dotty/tools/dotc/core
- tests/run
2 files changed
+10
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1029 | 1029 | | |
1030 | 1030 | | |
1031 | 1031 | | |
1032 | | - | |
| 1032 | + | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | | - | |
| 1038 | + | |
1039 | 1039 | | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
1043 | 1043 | | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | | - | |
| 1046 | + | |
| 1047 | + | |
1047 | 1048 | | |
1048 | 1049 | | |
1049 | 1050 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
68 | 74 | | |
69 | 75 | | |
0 commit comments