Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Nov 25, 2024
1 parent 91a5be5 commit ffac28b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/neg/seqlits.check
Original file line number Diff line number Diff line change
Expand Up @@ -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])
12 changes: 11 additions & 1 deletion tests/neg/seqlits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)


11 changes: 11 additions & 0 deletions tests/run/seqlits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit ffac28b

Please sign in to comment.