You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
objectTest {
// First example with a concrete type <: AnyValdefmain(args: Array[String]):Unit= {
valcoll=new java.util.ArrayList[Int]()
java.util.Collections.addAll(coll, 5, 6)
println(coll.size())
}
// Second example with an abstract type not known to be <: AnyRefdeffoo[A](a1: A, a2: A):Unit= {
valcoll=new java.util.ArrayList[A]()
java.util.Collections.addAll(coll, a1, a2)
println(coll.size())
}
}
Output
-- [E007] Type Mismatch Error: tests\run\hello.scala:5:39 ----------------------
5 | java.util.Collections.addAll(coll, 5, 6)
| ^
| Found: (5 : Int)
| Required: Int & Object
-- [E007] Type Mismatch Error: tests\run\hello.scala:5:42 ----------------------
5 | java.util.Collections.addAll(coll, 5, 6)
| ^
| Found: (6 : Int)
| Required: Int & Object
-- [E007] Type Mismatch Error: tests\run\hello.scala:12:39 ---------------------
12 | java.util.Collections.addAll(coll, a1, a2)
| ^^
| Found: (a1 : A)
| Required: A & Object
-- [E007] Type Mismatch Error: tests\run\hello.scala:12:43 ---------------------
12 | java.util.Collections.addAll(coll, a1, a2)
| ^^
| Found: (a2 : A)
| Required: A & Object
4 errors found
This is much more convenient for users but is more complicated for the
compiler since we still need to translate the varargs into an `Object[]`
in bytecode. Since ElimRepeated was already responsible for doing some
adaptation of repeated arguments, it now also takes care of this (this
differs from Scala 2 which handles this at Erasure).
Fixesscala#9439.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Jul 27, 2020
This is much more convenient for users but is more complicated for the
compiler since we still need to translate the varargs into an `Object[]`
in bytecode. Since ElimRepeated was already responsible for doing some
adaptation of repeated arguments, it now also takes care of this (this
differs from Scala 2 which handles this at Erasure).
Fixesscala#9439.
Minimized code
Output
Expectation
I expect that both examples compile.
Notes
JavaDoc of
java.util.Collections.addAll
This prevents the Scala.js test
CollectionsOnCollectionsTest
from compiling, at the following line:https://github.com/scala-js/scala-js/blob/6b9f04b0c0531d889235726d8956cb01a4c7476d/test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/CollectionsOnCollectionsTest.scala#L146
The text was updated successfully, but these errors were encountered: