aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/tailcall/t6574.scala4
-rw-r--r--tests/neg/variances.scala15
-rw-r--r--tests/pos/tailcall/i1089.scala26
-rw-r--r--tests/pos/variances.scala15
-rw-r--r--tests/repl/import.check11
-rw-r--r--tests/repl/imports.check24
-rw-r--r--tests/repl/multilines.check33
-rw-r--r--tests/repl/onePlusOne.check3
8 files changed, 129 insertions, 2 deletions
diff --git a/tests/neg/tailcall/t6574.scala b/tests/neg/tailcall/t6574.scala
index 7030b3b4a..d9ba2882d 100644
--- a/tests/neg/tailcall/t6574.scala
+++ b/tests/neg/tailcall/t6574.scala
@@ -4,7 +4,7 @@ class Bad[X, Y](val v: Int) extends AnyVal {
println("tail")
}
- @annotation.tailrec final def differentTypeArgs : Unit = {
- {(); new Bad[String, Unit](0)}.differentTypeArgs
+ @annotation.tailrec final def differentTypeArgs : Unit = { // error
+ {(); new Bad[String, Unit](0)}.differentTypeArgs // error
}
}
diff --git a/tests/neg/variances.scala b/tests/neg/variances.scala
index 71ee504bc..d732bb6db 100644
--- a/tests/neg/variances.scala
+++ b/tests/neg/variances.scala
@@ -41,4 +41,19 @@ object Test2 extends App {
}
+trait HasY { type Y }
+
+// These are neg-tests corresponding to the pos-test Variances.scala
+// where all the variance annotations have been inverted.
+trait Foo1[+X] { def bar[Y <: X](y: Y) = y } // error
+trait Foo2[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
+trait Foo3[-X] { def bar[Y >: X](y: Y) = y } // error
+trait Foo4[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
+
+// These are neg-tests corresponding to the pos-test Variances.scala
+// where all the bounds have been flipped.
+trait Foo5[-X] { def bar[Y >: X](y: Y) = y } // error
+trait Foo6[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
+trait Foo7[+X] { def bar[Y <: X](y: Y) = y } // error
+trait Foo8[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
diff --git a/tests/pos/tailcall/i1089.scala b/tests/pos/tailcall/i1089.scala
new file mode 100644
index 000000000..8eb69cb9b
--- /dev/null
+++ b/tests/pos/tailcall/i1089.scala
@@ -0,0 +1,26 @@
+package hello
+
+import scala.annotation.tailrec
+
+class Enclosing {
+ class SomeData(val x: Int)
+
+ def localDef(): Unit = {
+ def foo(data: SomeData): Int = data.x
+
+ @tailrec
+ def test(i: Int, data: SomeData): Unit = {
+ if (i != 0) {
+ println(foo(data))
+ test(i - 1, data)
+ }
+ }
+
+ test(3, new SomeData(42))
+ }
+}
+
+object world extends App {
+ println("hello dotty!")
+ new Enclosing().localDef()
+}
diff --git a/tests/pos/variances.scala b/tests/pos/variances.scala
index db858fd5d..7ab9fe72a 100644
--- a/tests/pos/variances.scala
+++ b/tests/pos/variances.scala
@@ -1,3 +1,18 @@
trait C[+T <: C[T, U], -U <: C[T, U]] {
}
+trait HasY { type Y }
+
+// This works in scalac.
+trait Foo1[-X] { def bar[Y <: X](y: Y) = y }
+
+// A variant of Foo1 using a dependent method type (doesn't work using
+// scalac)
+trait Foo2[-X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y }
+
+// This works in scalac.
+trait Foo3[+X] { def bar[Y >: X](y: Y) = y }
+
+// A variant of Foo3 using a dependent method type (doesn't work
+// using scalac)
+trait Foo4[+X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y }
diff --git a/tests/repl/import.check b/tests/repl/import.check
new file mode 100644
index 000000000..ccaa52190
--- /dev/null
+++ b/tests/repl/import.check
@@ -0,0 +1,11 @@
+scala> import collection.mutable._
+import collection.mutable._
+scala> val buf = new ListBuffer[Int]
+buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
+scala> buf += 22
+res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(22)
+scala> buf ++= List(1, 2, 3)
+res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(22, 1, 2, 3)
+scala> buf.toList
+res2: scala.collection.immutable.List[Int] = List(22, 1, 2, 3)
+scala> :quit
diff --git a/tests/repl/imports.check b/tests/repl/imports.check
new file mode 100644
index 000000000..3fa103283
--- /dev/null
+++ b/tests/repl/imports.check
@@ -0,0 +1,24 @@
+scala> import scala.collection.mutable
+import scala.collection.mutable
+scala> val buf = mutable.ListBuffer[Int]()
+buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
+scala> object o {
+ | val xs = List(1, 2, 3)
+ | }
+defined module o
+scala> import o._
+import o._
+scala> buf += xs
+<console>:11: error: type mismatch:
+ found : scala.collection.immutable.List[Int](o.xs)
+ required: String
+buf += xs
+ ^
+<console>:11: error: type mismatch:
+ found : String
+ required: scala.collection.mutable.ListBuffer[Int]
+buf += xs
+^
+scala> buf ++= xs
+res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
+scala> :quit
diff --git a/tests/repl/multilines.check b/tests/repl/multilines.check
new file mode 100644
index 000000000..3bc32707e
--- /dev/null
+++ b/tests/repl/multilines.check
@@ -0,0 +1,33 @@
+scala> val x = """alpha
+ |
+ | omega"""
+x: String =
+alpha
+
+omega
+scala> val y = """abc
+ | |def
+ | |ghi
+ | """.stripMargin
+y: String =
+abc
+def
+ghi
+
+scala> val z = {
+ | def square(x: Int) = x * x
+ | val xs = List(1, 2, 3)
+ | square(xs)
+ | }
+<console>:8: error: type mismatch:
+ found : scala.collection.immutable.List[Int](xs)
+ required: Int
+ square(xs)
+ ^
+scala> val z = {
+ | def square(x: Int) = x * x
+ | val xs = List(1, 2, 3)
+ | xs.map(square)
+ | }
+z: scala.collection.immutable.List[Int] = List(1, 4, 9)
+scala> :quit
diff --git a/tests/repl/onePlusOne.check b/tests/repl/onePlusOne.check
new file mode 100644
index 000000000..9db6e6817
--- /dev/null
+++ b/tests/repl/onePlusOne.check
@@ -0,0 +1,3 @@
+scala> 1+1
+res0: Int = 2
+scala> :quit