Open
Description
This happens when vararg type has type parameters.
Both Array and mutable.Seq are invariant. However using Array as an argument in vararg function fails, while mutable.Seq works.
object Main {
def main(args: Array[String]) {
bar(new B)
}
def bar(b: B) {
val array = Array(b, b)
val seq :scala.collection.mutable.Seq[B] = array
foo(b, b)
foo(seq: _*) //works
foo(array: _*) //compiler error
}
def foo(s: A[_]*) {
s.foreach(println)
}
}
class A[T]
class B extends A[String]
Compiler error:
error: type mismatch;
found : Array[B]
required: Array[A[?>: Nothing <: Any]]
foo(array: _*)
one error found
Everything works when vararg type does not have any type parameters:
object Main {
def main(args: Array[String]) {
bar(new B)
}
def bar(b: B) {
val array = Array(b, b)
val seq :scala.collection.mutable.Seq[B] = array
foo(b, b)
foo(seq: _*)
foo(array: _*)
}
def foo[T](s: A*) {
s.foreach(println)
}
}
class A
class B extends A
Tested on 2.8.1.final and 2.9.0.r23541.