diff --git a/tests/neg/seqlits.check b/tests/neg/seqlits.check index d68dce39b9cd..67e9c0e6120f 100644 --- a/tests/neg/seqlits.check +++ b/tests/neg/seqlits.check @@ -30,3 +30,17 @@ | Required: (scala.collection.immutable.BitSet, Seq[Int]) | | longer explanation available when compiling with `-explain` +-- [E134] Type Error: tests/neg/seqlits.scala:30:11 -------------------------------------------------------------------- +30 | val xx = f([1, 2, 3]) // error: no matching alternatives for Seq[Int] + | ^ + | None of the overloaded alternatives of method f in object SeqLits with types + | [A](xs: Vector[A]): Vector[A] + | [A](xs: List[A]): List[A] + | match arguments (Seq[Int]) +-- [E134] Type Error: tests/neg/seqlits.scala:34:11 -------------------------------------------------------------------- +34 | val yy = g([1, 2, 3]) // error: no matching alternatives for Seq[Int] (even if one method is more specific than the other) + | ^ + | None of the overloaded alternatives of method g in object SeqLits with types + | [A](xs: scala.collection.immutable.HashSet[A]): Set[A] + | [A](xs: Set[A]): Set[A] + | match arguments (Seq[Int]) diff --git a/tests/neg/seqlits.scala b/tests/neg/seqlits.scala index 9739255aa218..c3166e925a61 100644 --- a/tests/neg/seqlits.scala +++ b/tests/neg/seqlits.scala @@ -23,4 +23,14 @@ object SeqLits: val x: A = [1, 2, 3] // error: ambiguous val y: D = [1, 2, 3] // error: type mismatch - val mbss: Map[BitSet, Seq[Int]] = [[1] -> [1], [0, 2] -> [1, 2], [0] -> []] // error: type mismatch // error // error \ No newline at end of file + val mbss: Map[BitSet, Seq[Int]] = [[1] -> [1], [0, 2] -> [1, 2], [0] -> []] // error: type mismatch // error // error + + def f[A](xs: List[A]) = xs + def f[A](xs: Vector[A]) = xs + val xx = f([1, 2, 3]) // error: no matching alternatives for Seq[Int] + + def g[A](xs: Set[A]): Set[A] = xs + def g[A](xs: collection.immutable.HashSet[A]): Set[A] = xs + val yy = g([1, 2, 3]) // error: no matching alternatives for Seq[Int] (even if one method is more specific than the other) + + diff --git a/tests/run/seqlits.scala b/tests/run/seqlits.scala index f23370186af1..074dc9530d93 100644 --- a/tests/run/seqlits.scala +++ b/tests/run/seqlits.scala @@ -16,6 +16,12 @@ object SeqLits: def last: Int = { println("last was evaluated"); 4 } + def f1[A](xs: A, ys: A) = ys + def f2[A](xs: Vector[A]) = xs + + def g[A](xs: Set[A]): Set[A] = xs + def g[A](xs: collection.immutable.HashSet[A]): Set[A] = xs + @main def Test = val s: Seq[Int] = [1, 2, 3, last] val v: Vector[Int] = [1, 2, 3, last] @@ -42,6 +48,11 @@ object SeqLits: // val mbss: Map[BitSet, Seq[Int]] = [[1] -> [1], [0, 2] -> [1, 2], [0] -> []] // error: keys get default value Seq val mbss: Map[BitSet, Seq[Int]] = [([1], [1]), ([0, 2], [1, 2]), ([0], [])] // ok + val x1 = f1(Vector(1, 2, 3), [3, 4, 5]) + val _: Seq[Int] = x1 + val x2 = f2([1, 2, 3]) + val _: Vector[Int] = x2 + println(s"Seq $s") println(s"Vector $v") println(bs)