Commit dbb98b3
committed
Don't drop Object intersection for varargs
A Java generic array `T[]` is unpickled in ClassfileParser to `Array[T &
Object]`, because it will not accept primitive arrays. However, Java
varargs were special-cased to drop this intersection. Erasure contained
some code to compensate for this, but this is still unsound and lead to
tests/run/t1360.scala failing with a ClassCastException.
Thanks to #8669 we can drop this special-casing of varargs without
affecting typing too much: it's still possible to pass `Array(1, 2): _*`
where `(T & Object)*` is expected because adaptation will take care of
boxing.
One test case had to be adapted, I replaced:
def apply[X](xs : X*): java.util.List[X]
java.util.Arrays.asList(xs: _*)
with:
def apply[X <: AnyRef](xs : X*): java.util.List[X] =
java.util.Arrays.asList(xs: _*)
I don't think that's too constraining.
Note: after this commit, tests/run/i533 started failing, this is fixed
in the next commit.1 parent c80d6e4 commit dbb98b3
File tree
5 files changed
+7
-20
lines changed- compiler/src/dotty/tools/dotc
- core/unpickleScala2
- transform
- tests
- pos
- run/java-varargs
5 files changed
+7
-20
lines changedLines changed: 1 addition & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 70 | | |
84 | 71 | | |
85 | | - | |
| 72 | + | |
86 | 73 | | |
87 | 74 | | |
88 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | 312 | | |
318 | 313 | | |
319 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
0 commit comments