summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/continuations-neg/trycatch2.scala6
-rw-r--r--test/files/neg/catch-all.check10
-rw-r--r--test/files/neg/catch-all.flags1
-rw-r--r--test/files/neg/catch-all.scala19
-rw-r--r--test/files/neg/t4989.check7
-rw-r--r--test/files/neg/t4989.scala68
-rw-r--r--test/files/pos/spec-params-new.scala2
-rw-r--r--test/files/pos/t5968.flags1
-rw-r--r--test/files/pos/t5968.scala8
-rw-r--r--test/files/run/t4809.scala34
-rw-r--r--test/files/run/t5284.check1
-rw-r--r--test/files/run/t5284.scala25
-rw-r--r--test/files/run/t5284b.check1
-rw-r--r--test/files/run/t5284b.scala28
-rw-r--r--test/files/run/t5284c.check1
-rw-r--r--test/files/run/t5284c.scala30
16 files changed, 238 insertions, 4 deletions
diff --git a/test/files/continuations-neg/trycatch2.scala b/test/files/continuations-neg/trycatch2.scala
index d61419169b..d329a3b530 100644
--- a/test/files/continuations-neg/trycatch2.scala
+++ b/test/files/continuations-neg/trycatch2.scala
@@ -12,7 +12,7 @@ object Test {
fatal[Int]
cpsIntStringInt
} catch {
- case ex =>
+ case ex: Throwable =>
cpsIntStringInt
}
@@ -20,7 +20,7 @@ object Test {
fatal[Int]
cpsIntStringInt
} catch {
- case ex =>
+ case ex: Throwable =>
cpsIntStringInt
}
@@ -30,4 +30,4 @@ object Test {
println(reset { foo2; "3" })
}
-} \ No newline at end of file
+}
diff --git a/test/files/neg/catch-all.check b/test/files/neg/catch-all.check
new file mode 100644
index 0000000000..ab3d28777d
--- /dev/null
+++ b/test/files/neg/catch-all.check
@@ -0,0 +1,10 @@
+catch-all.scala:2: error: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
+ try { "warn" } catch { case _ => }
+ ^
+catch-all.scala:4: error: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
+ try { "warn" } catch { case x => }
+ ^
+catch-all.scala:6: error: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
+ try { "warn" } catch { case _: RuntimeException => ; case x => }
+ ^
+three errors found
diff --git a/test/files/neg/catch-all.flags b/test/files/neg/catch-all.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/catch-all.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/catch-all.scala b/test/files/neg/catch-all.scala
new file mode 100644
index 0000000000..35a6d7af91
--- /dev/null
+++ b/test/files/neg/catch-all.scala
@@ -0,0 +1,19 @@
+object CatchAll {
+ try { "warn" } catch { case _ => }
+
+ try { "warn" } catch { case x => }
+
+ try { "warn" } catch { case _: RuntimeException => ; case x => }
+
+ try { "okay" } catch { case _: Throwable => }
+
+ try { "okay" } catch { case _: Exception => }
+
+ try { "okay" } catch { case okay: Throwable => }
+
+ try { "okay" } catch { case okay: Exception => }
+
+ try { "okay" } catch { case _ if "".isEmpty => }
+
+ "okay" match { case _ => "" }
+}
diff --git a/test/files/neg/t4989.check b/test/files/neg/t4989.check
new file mode 100644
index 0000000000..814507fc3f
--- /dev/null
+++ b/test/files/neg/t4989.check
@@ -0,0 +1,7 @@
+t4989.scala:14: error: method print in class A cannot be directly accessed from class C because class B redeclares it as abstract
+ override def print(): String = super.print() // should be an error
+ ^
+t4989.scala:18: error: method print in class A cannot be directly accessed from trait T because class B redeclares it as abstract
+ override def print(): String = super.print() // should be an error
+ ^
+two errors found
diff --git a/test/files/neg/t4989.scala b/test/files/neg/t4989.scala
new file mode 100644
index 0000000000..e7ff80ed74
--- /dev/null
+++ b/test/files/neg/t4989.scala
@@ -0,0 +1,68 @@
+abstract class A0 {
+ def print(): String
+}
+
+class A extends A0 {
+ def print(): String = "A"
+}
+
+abstract class B extends A {
+ def print() : String
+}
+
+class C extends B {
+ override def print(): String = super.print() // should be an error
+}
+
+trait T extends B {
+ override def print(): String = super.print() // should be an error
+}
+
+class D extends A {
+ override def print(): String = super.print() // okay
+}
+
+
+// it's okay do this when trait are in the mix, as the
+// suitable super accessor methods are used.
+object ConcreteMethodAndIntermediaryAreTraits {
+ trait T1 {
+ def print(): String = ""
+ }
+
+ trait T2 extends T1 {
+ def print(): String
+ }
+
+ class C3 extends T2 {
+ def print(): String = super.print() // okay
+ }
+}
+
+object IntermediaryIsTrait {
+ class T1 {
+ def print(): String = ""
+ }
+
+ trait T2 extends T1 {
+ def print(): String
+ }
+
+ class C3 extends T2 {
+ override def print(): String = super.print() // okay
+ }
+}
+
+object ConcreteMethodIsTrait {
+ trait T1 {
+ def print(): String = ""
+ }
+
+ abstract class T2 extends T1 {
+ def print(): String
+ }
+
+ class C3 extends T2 {
+ override def print(): String = super.print() // okay
+ }
+}
diff --git a/test/files/pos/spec-params-new.scala b/test/files/pos/spec-params-new.scala
index 661e686f0e..959ce1591c 100644
--- a/test/files/pos/spec-params-new.scala
+++ b/test/files/pos/spec-params-new.scala
@@ -31,4 +31,4 @@ class Foo[@specialized A: ClassTag] {
val xs = new Array[A](1)
xs(0) = x
}
-} \ No newline at end of file
+}
diff --git a/test/files/pos/t5968.flags b/test/files/pos/t5968.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/pos/t5968.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/pos/t5968.scala b/test/files/pos/t5968.scala
new file mode 100644
index 0000000000..0093f84fc0
--- /dev/null
+++ b/test/files/pos/t5968.scala
@@ -0,0 +1,8 @@
+object X {
+ def f(e: Either[Int, X.type]) = e match {
+ case Left(i) => i
+ case Right(X) => 0
+ // SI-5986 spurious exhaustivity warning here
+ }
+}
+
diff --git a/test/files/run/t4809.scala b/test/files/run/t4809.scala
new file mode 100644
index 0000000000..b30d80562f
--- /dev/null
+++ b/test/files/run/t4809.scala
@@ -0,0 +1,34 @@
+
+
+import scala.util.control.Breaks._
+
+
+
+object Test {
+
+ def main(args: Array[String]) {
+ val x = tryBreakable {
+ break
+ 2
+ } catchBreak {
+ 3
+ }
+ assert(x == 3, x)
+
+ val y = tryBreakable {
+ 2
+ } catchBreak {
+ 3
+ }
+ assert(y == 2, y)
+
+ val z = tryBreakable {
+ break
+ 1.0
+ } catchBreak {
+ 2
+ }
+ assert(z == 2.0, z)
+ }
+
+}
diff --git a/test/files/run/t5284.check b/test/files/run/t5284.check
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/files/run/t5284.check
@@ -0,0 +1 @@
+2
diff --git a/test/files/run/t5284.scala b/test/files/run/t5284.scala
new file mode 100644
index 0000000000..ba0845fb8e
--- /dev/null
+++ b/test/files/run/t5284.scala
@@ -0,0 +1,25 @@
+
+
+
+
+
+/** Here we have a situation where a normalized method parameter `W`
+ * is used in a position which accepts an instance of type `T` - we know we can
+ * safely cast `T` to `W` whenever type bounds on `W` hold.
+ */
+object Test {
+ def main(args: Array[String]) {
+ val a = Blarg(Array(1, 2, 3))
+ println(a.m((x: Int) => x + 1))
+ }
+}
+
+
+object Blarg {
+ def apply[T: Manifest](a: Array[T]) = new Blarg(a)
+}
+
+
+class Blarg[@specialized(Int) T: Manifest](val a: Array[T]) {
+ def m[@specialized(Int) W >: T, @specialized(Int) S](f: W => S) = f(a(0))
+}
diff --git a/test/files/run/t5284b.check b/test/files/run/t5284b.check
new file mode 100644
index 0000000000..98d9bcb75a
--- /dev/null
+++ b/test/files/run/t5284b.check
@@ -0,0 +1 @@
+17
diff --git a/test/files/run/t5284b.scala b/test/files/run/t5284b.scala
new file mode 100644
index 0000000000..a9282a895f
--- /dev/null
+++ b/test/files/run/t5284b.scala
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+/** Here we have a situation where a normalized method parameter `W`
+ * is used in a position which expects a type `T` - we know we can
+ * safely cast `W` to `T` whenever typebounds of `W` hold.
+ */
+object Test {
+ def main(args: Array[String]) {
+ val foo = Foo.createUnspecialized[Int]
+ println(foo.bar(17))
+ }
+}
+
+
+object Foo {
+ def createUnspecialized[T] = new Foo[T]
+}
+
+
+class Foo[@specialized(Int) T] {
+ val id: T => T = x => x
+
+ def bar[@specialized(Int) W <: T, @specialized(Int) S](w: W) = id(w)
+}
diff --git a/test/files/run/t5284c.check b/test/files/run/t5284c.check
new file mode 100644
index 0000000000..00750edc07
--- /dev/null
+++ b/test/files/run/t5284c.check
@@ -0,0 +1 @@
+3
diff --git a/test/files/run/t5284c.scala b/test/files/run/t5284c.scala
new file mode 100644
index 0000000000..383b84c2cc
--- /dev/null
+++ b/test/files/run/t5284c.scala
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+/** Here we have a compound type `List[W]` used in
+ * a position where `List[T]` is expected. The cast
+ * emitted in the normalized `bar` is safe because the
+ * normalized `bar` can only be called if the type
+ * bounds hold.
+ */
+object Test {
+ def main(args: Array[String]) {
+ val foo = Foo.createUnspecialized[Int]
+ println(foo.bar(List(1, 2, 3)))
+ }
+}
+
+
+object Foo {
+ def createUnspecialized[T] = new Foo[T]
+}
+
+
+class Foo[@specialized(Int) T] {
+ val len: List[T] => Int = xs => xs.length
+
+ def bar[@specialized(Int) W <: T](ws: List[W]) = len(ws)
+}