summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/t9398.check7
-rw-r--r--test/files/neg/t9398.flags1
-rw-r--r--test/files/neg/t9398/data.scala5
-rw-r--r--test/files/neg/t9398/match.scala6
-rw-r--r--test/files/neg/t9629.check17
-rw-r--r--test/files/neg/t9629.scala12
-rw-r--r--test/files/pos/t5899.scala1
-rw-r--r--test/files/pos/t9399.flags1
-rw-r--r--test/files/pos/t9399.scala17
-rw-r--r--test/files/pos/t9411a.flags1
-rw-r--r--test/files/pos/t9411a.scala27
-rw-r--r--test/files/pos/t9411b.flags1
-rw-r--r--test/files/pos/t9411b.scala36
-rw-r--r--test/files/pos/t9630.flags1
-rw-r--r--test/files/pos/t9630/t9630a.scala9
-rw-r--r--test/files/pos/t9630/t9630b.scala8
-rw-r--r--test/files/run/Course-2002-07.scala2
-rw-r--r--test/files/run/caseclasses.scala2
-rw-r--r--test/files/run/infix.scala1
-rw-r--r--test/files/run/patmatnew.scala4
-rw-r--r--test/files/run/t3126.scala2
-rw-r--r--test/files/run/t4124.scala8
-rw-r--r--test/files/run/t6089.scala2
-rw-r--r--test/files/run/t7459f.scala2
-rw-r--r--test/junit/scala/collection/ReusableBuildersTest.scala48
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/StringConcatTest.scala70
-rw-r--r--test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala2
-rw-r--r--test/scaladoc/resources/SI-9599.scala6
-rw-r--r--test/scaladoc/scalacheck/HtmlFactoryTest.scala7
29 files changed, 294 insertions, 12 deletions
diff --git a/test/files/neg/t9398.check b/test/files/neg/t9398.check
new file mode 100644
index 0000000000..f0c464daa1
--- /dev/null
+++ b/test/files/neg/t9398.check
@@ -0,0 +1,7 @@
+match.scala:3: warning: match may not be exhaustive.
+It would fail on the following input: CC(B2)
+ def test(c: CC): Unit = c match {
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/t9398.flags b/test/files/neg/t9398.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/t9398.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/t9398/data.scala b/test/files/neg/t9398/data.scala
new file mode 100644
index 0000000000..7a98c0e8e8
--- /dev/null
+++ b/test/files/neg/t9398/data.scala
@@ -0,0 +1,5 @@
+sealed abstract class TB
+case object B extends TB
+case object B2 extends TB
+
+case class CC(tb: TB)
diff --git a/test/files/neg/t9398/match.scala b/test/files/neg/t9398/match.scala
new file mode 100644
index 0000000000..e110c6a96a
--- /dev/null
+++ b/test/files/neg/t9398/match.scala
@@ -0,0 +1,6 @@
+class Test {
+ // Should warn that CC(B2) isn't matched
+ def test(c: CC): Unit = c match {
+ case CC(B) => ()
+ }
+}
diff --git a/test/files/neg/t9629.check b/test/files/neg/t9629.check
new file mode 100644
index 0000000000..4eafa84236
--- /dev/null
+++ b/test/files/neg/t9629.check
@@ -0,0 +1,17 @@
+t9629.scala:4: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case Option[Int] => // error was issued before
+ ^
+t9629.scala:5: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case Some(Option[Int]) => // error was skipped, patmat issued an internal error
+ ^
+t9629.scala:8: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case (_, Option[Int]) =>
+ ^
+t9629.scala:9: error: pattern must be a value: Option[Int]
+Note: if you intended to match against the class, try `case _: Option[_]`
+ case x @ (y @ Option[Int]) =>
+ ^
+four errors found
diff --git a/test/files/neg/t9629.scala b/test/files/neg/t9629.scala
new file mode 100644
index 0000000000..2be2b039f2
--- /dev/null
+++ b/test/files/neg/t9629.scala
@@ -0,0 +1,12 @@
+class Test {
+ def foo(a: Any) {
+ a match {
+ case Option[Int] => // error was issued before
+ case Some(Option[Int]) => // error was skipped, patmat issued an internal error
+
+ // variations
+ case (_, Option[Int]) =>
+ case x @ (y @ Option[Int]) =>
+ }
+ }
+}
diff --git a/test/files/pos/t5899.scala b/test/files/pos/t5899.scala
index b16f1f84fe..885baca790 100644
--- a/test/files/pos/t5899.scala
+++ b/test/files/pos/t5899.scala
@@ -14,6 +14,7 @@ trait Foo {
Bippy(Stable) match {
case Bippy(nme.WILDCARD) => 1
case Bippy(Stable) => 2 // should not be considered unreachable
+ case Bippy(_) => 3
}
}
} \ No newline at end of file
diff --git a/test/files/pos/t9399.flags b/test/files/pos/t9399.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/pos/t9399.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/pos/t9399.scala b/test/files/pos/t9399.scala
new file mode 100644
index 0000000000..e8a8720f94
--- /dev/null
+++ b/test/files/pos/t9399.scala
@@ -0,0 +1,17 @@
+sealed abstract class TA
+sealed abstract class TB extends TA
+case object A extends TA
+case object B extends TB
+
+sealed trait C
+case class CTA(id: Int, da: TA) extends C
+case class CTB(id: Int, da: TB) extends C
+
+class Test {
+ def test(c: C): Unit = c match {
+ case CTA(_, A) =>
+ case CTA(_, B) =>
+ case CTB(_, B) =>
+ }
+}
+
diff --git a/test/files/pos/t9411a.flags b/test/files/pos/t9411a.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/pos/t9411a.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/pos/t9411a.scala b/test/files/pos/t9411a.scala
new file mode 100644
index 0000000000..d5264663ec
--- /dev/null
+++ b/test/files/pos/t9411a.scala
@@ -0,0 +1,27 @@
+object OhNoes {
+
+ sealed trait F
+ sealed abstract class FA extends F
+ sealed abstract class FB extends F
+
+ case object FA1 extends FA
+ case object FB1 extends FB
+ case object FB2 extends FB
+
+ sealed trait G
+ case object G1 extends G
+ case object G2 extends G
+
+ sealed trait H
+ case class H1(a: FB, b: G) extends H
+ case class H2(a: F) extends H
+
+ val demo: H => Unit = {
+ case H1(FB1, G1) =>
+ case H1(FB2, G2) =>
+ case H2(_: FB) =>
+ case H2(_: FA) =>
+ case H1(FB1, G2) =>
+ case H1(FB2, G1) =>
+ }
+}
diff --git a/test/files/pos/t9411b.flags b/test/files/pos/t9411b.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/pos/t9411b.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/pos/t9411b.scala b/test/files/pos/t9411b.scala
new file mode 100644
index 0000000000..6888ba9382
--- /dev/null
+++ b/test/files/pos/t9411b.scala
@@ -0,0 +1,36 @@
+object OhNoes {
+
+ sealed trait F
+ sealed abstract class FA extends F
+ sealed abstract class FB extends F
+
+ case object FA1 extends FA
+ case object FB1 extends FB
+ case object FB2 extends FB
+
+ sealed trait G
+ case object G1 extends G
+ case object G2 extends G
+
+ sealed trait H
+ case class H1(a: FB, b: G) extends H
+ case class H2(b: F) extends H
+
+ val demo: H => Unit = {
+ case H1(FB1, G1) =>
+ case H1(FB2, G2) =>
+ case H2(_: FB) =>
+ case H2(_: FA) =>
+ case H1(FB1, G2) =>
+ case H1(FB2, G1) =>
+ }
+
+ val demo2: H => Unit = {
+ case H2(_: FA) =>
+ case H2(_: FB) =>
+ case H1(FB1, G1) =>
+ case H1(FB2, G1) =>
+ case H1(FB1, G2) =>
+ case H1(FB2, G2) =>
+ }
+}
diff --git a/test/files/pos/t9630.flags b/test/files/pos/t9630.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/pos/t9630.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/pos/t9630/t9630a.scala b/test/files/pos/t9630/t9630a.scala
new file mode 100644
index 0000000000..c76ecd2ff2
--- /dev/null
+++ b/test/files/pos/t9630/t9630a.scala
@@ -0,0 +1,9 @@
+
+sealed trait Base
+final case class Base_1(sameName: Some[Any]) extends Base
+final case class Base_2(sameName: Nested) extends Base
+
+sealed trait Nested
+final case class Nested_1(x: Any) extends Nested
+final case class Nested_2(y: Any) extends Nested
+
diff --git a/test/files/pos/t9630/t9630b.scala b/test/files/pos/t9630/t9630b.scala
new file mode 100644
index 0000000000..3e1787ec52
--- /dev/null
+++ b/test/files/pos/t9630/t9630b.scala
@@ -0,0 +1,8 @@
+
+class Test {
+ def test(b: Base): Unit = b match {
+ case Base_1(Some(_)) =>
+ case Base_2(Nested_1(_)) =>
+ case Base_2(Nested_2(_)) =>
+ }
+}
diff --git a/test/files/run/Course-2002-07.scala b/test/files/run/Course-2002-07.scala
index 2d9457653f..db6e1d8e04 100644
--- a/test/files/run/Course-2002-07.scala
+++ b/test/files/run/Course-2002-07.scala
@@ -485,7 +485,7 @@ object MB {
import Utils._;
- trait Expr {
+ sealed trait Expr {
private def count: Int = this match {
case Lit(n) => n
diff --git a/test/files/run/caseclasses.scala b/test/files/run/caseclasses.scala
index 668c984f3d..10c0916dc0 100644
--- a/test/files/run/caseclasses.scala
+++ b/test/files/run/caseclasses.scala
@@ -18,7 +18,7 @@ object M {
object Test extends App {
def Abs(x: Int) = new Abs(x * 2){}
- Abs(2) match {
+ (Abs(2): @unchecked) match {
case Abs(4) => ;
}
diff --git a/test/files/run/infix.scala b/test/files/run/infix.scala
index a867d03ce8..1d39003644 100644
--- a/test/files/run/infix.scala
+++ b/test/files/run/infix.scala
@@ -7,5 +7,6 @@ object Test extends App {
Console.println(xs)
xs match {
case null op (0, 0) op (1, 1) op (2, 2) => Console.println("OK")
+ case _ =>
}
}
diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala
index 3c0d00dc6c..2647d97836 100644
--- a/test/files/run/patmatnew.scala
+++ b/test/files/run/patmatnew.scala
@@ -539,7 +539,7 @@ object Test {
case class Operator(x: Int);
val EQ = new Operator(2);
- def analyze(x: Tuple2[Operator, Int]) = x match {
+ def analyze(x: Tuple2[Operator, Int]) = (x: @unchecked) match {
case (EQ, 0) => "0"
case (EQ, 1) => "1"
case (EQ, 2) => "2"
@@ -603,7 +603,7 @@ object Test {
object Bug1093 {
def run() {
- assert(Some(3) match {
+ assert((Some(3): @unchecked) match {
case Some(1 | 2) => false
case Some(3) => true
})
diff --git a/test/files/run/t3126.scala b/test/files/run/t3126.scala
index 36322bf896..865047ce4f 100644
--- a/test/files/run/t3126.scala
+++ b/test/files/run/t3126.scala
@@ -4,6 +4,6 @@ object Test {
def main(args: Array[String]): Unit = {
try C.unapply(null) catch { case _: MatchError => }
- try v match { case Some(1) => } catch { case _: MatchError => }
+ try ((v: @unchecked) match { case Some(1) => }) catch { case _: MatchError => }
}
}
diff --git a/test/files/run/t4124.scala b/test/files/run/t4124.scala
index 9f35b57ce3..db4e382634 100644
--- a/test/files/run/t4124.scala
+++ b/test/files/run/t4124.scala
@@ -2,22 +2,22 @@ import xml.Node
object Test extends App {
val body: Node = <elem>hi</elem>
- println ((body: AnyRef, "foo") match {
+ println (((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "bar") => "bye"
case (ser: Serializable, "foo") => "hi"
})
- println ((body, "foo") match {
+ println (((body, "foo"): @unchecked) match {
case (node: Node, "bar") => "bye"
case (ser: Serializable, "foo") => "hi"
})
- println ((body: AnyRef, "foo") match {
+ println (((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "foo") => "bye"
case (ser: Serializable, "foo") => "hi"
})
- println ((body: AnyRef, "foo") match {
+ println (((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "foo") => "bye"
case (ser: Serializable, "foo") => "hi"
})
diff --git a/test/files/run/t6089.scala b/test/files/run/t6089.scala
index c72d7ba792..c42a9f68c6 100644
--- a/test/files/run/t6089.scala
+++ b/test/files/run/t6089.scala
@@ -3,7 +3,7 @@ case class Foo(x: Int)
object Test {
def bippo(result: Boolean): Boolean = result
def bungus(m: Foo): Boolean =
- bippo(m match { case Foo(2) => bungus(m) })
+ bippo((m: @unchecked) match { case Foo(2) => bungus(m) })
def main(args: Array[String]): Unit = try {
bungus(Foo(0))
diff --git a/test/files/run/t7459f.scala b/test/files/run/t7459f.scala
index 63e2109560..5cd972129a 100644
--- a/test/files/run/t7459f.scala
+++ b/test/files/run/t7459f.scala
@@ -3,7 +3,7 @@ object Test extends App {
case class FooSeq(x: Int, y: String, z: C*)
- FooSeq(1, "a", new C()) match {
+ (FooSeq(1, "a", new C()): @unchecked) match {
case FooSeq(1, "a", x@_* ) =>
//println(x.toList)
x.asInstanceOf[x.type]
diff --git a/test/junit/scala/collection/ReusableBuildersTest.scala b/test/junit/scala/collection/ReusableBuildersTest.scala
new file mode 100644
index 0000000000..8dd1a37adf
--- /dev/null
+++ b/test/junit/scala/collection/ReusableBuildersTest.scala
@@ -0,0 +1,48 @@
+package scala.collection
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+
+/* Tests various maps by making sure they all agree on the same answers. */
+@RunWith(classOf[JUnit4])
+class ReusableBuildersTest {
+ // GrowingBuilders are NOT reusable but can clear themselves
+ @Test
+ def test_SI8648() {
+ val b = collection.mutable.HashSet.newBuilder[Int]
+ b += 3
+ b.clear
+ assert(!b.isInstanceOf[collection.mutable.ReusableBuilder[_,_]])
+ assert(b.isInstanceOf[collection.mutable.GrowingBuilder[_,_]])
+ assert(b.result == Set[Int]())
+ }
+
+ // ArrayBuilders ARE reusable, regardless of whether they returned their internal array or not
+ @Test
+ def test_SI9564() {
+ val b = Array.newBuilder[Float]
+ b += 3f
+ val three = b.result
+ b.clear
+ b ++= (1 to 16).map(_.toFloat)
+ val sixteen = b.result
+ b.clear
+ b += 0f
+ val zero = b.result
+ assert(b.isInstanceOf[collection.mutable.ReusableBuilder[_,_]])
+ assert(three.toList == 3 :: Nil)
+ assert(sixteen.toList == (1 to 16))
+ assert(zero.toList == 0 :: Nil)
+ }
+
+ @Test
+ def test_reusability() {
+ val bl = List.newBuilder[String]
+ val bv = Vector.newBuilder[String]
+ val ba = collection.mutable.ArrayBuffer.newBuilder[String]
+ assert(bl.isInstanceOf[collection.mutable.ReusableBuilder[_, _]])
+ assert(bv.isInstanceOf[collection.mutable.ReusableBuilder[_, _]])
+ assert(!ba.isInstanceOf[collection.mutable.ReusableBuilder[_, _]])
+ }
+}
diff --git a/test/junit/scala/tools/nsc/backend/jvm/StringConcatTest.scala b/test/junit/scala/tools/nsc/backend/jvm/StringConcatTest.scala
new file mode 100644
index 0000000000..80cde6c9a9
--- /dev/null
+++ b/test/junit/scala/tools/nsc/backend/jvm/StringConcatTest.scala
@@ -0,0 +1,70 @@
+package scala.tools.nsc
+package backend.jvm
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+import scala.tools.asm.Opcodes._
+import org.junit.Assert._
+
+import scala.tools.testing.AssertUtil._
+
+import CodeGenTools._
+import scala.tools.partest.ASMConverters
+import ASMConverters._
+import scala.tools.testing.ClearAfterClass
+
+object StringConcatTest extends ClearAfterClass.Clearable {
+ var compiler = newCompiler()
+ def clear(): Unit = { compiler = null }
+}
+
+@RunWith(classOf[JUnit4])
+class StringConcatTest extends ClearAfterClass {
+ ClearAfterClass.stateToClear = StringConcatTest
+ val compiler = StringConcatTest.compiler
+
+ val commonPreInstructions = List(Label(0), LineNumber(1, Label(0)), TypeOp(NEW, "java/lang/StringBuilder"), Op(DUP), Invoke(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false), Ldc(LDC, "abc"), Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false), VarOp(ALOAD, 0))
+
+ val commonPostInstructions = List(Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false), Op(ARETURN), Label(12))
+
+ def instructionsWithCommonParts(instructions: List[Instruction]) = commonPreInstructions ++ instructions ++ commonPostInstructions
+
+ def instructionsForResultMethod(code: String): List[Instruction] = {
+ val methods = compileMethods(compiler)(code)
+ val resultMethod = methods.find(_.name == "result").get
+ instructionsFromMethod(resultMethod)
+ }
+
+ @Test
+ def concatStringToStringBuilder: Unit = {
+ val code = """ def string = "def"; def result = "abc" + string """
+ val actualInstructions = instructionsForResultMethod(code)
+ val expectedInstructions = instructionsWithCommonParts(List(Invoke(INVOKEVIRTUAL, "C", "string", "()Ljava/lang/String;", false), Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)))
+ assertSameCode(actualInstructions, expectedInstructions)
+ }
+
+ @Test
+ def concatStringBufferToStringBuilder: Unit = {
+ val code = """ def stringBuffer = new java.lang.StringBuffer("def"); def result = "abc" + stringBuffer """
+ val actualInstructions = instructionsForResultMethod(code)
+ val expectedInstructions = instructionsWithCommonParts(List(Invoke(INVOKEVIRTUAL, "C", "stringBuffer", "()Ljava/lang/StringBuffer;", false), Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/StringBuffer;)Ljava/lang/StringBuilder;", false)))
+ assertSameCode(actualInstructions, expectedInstructions)
+ }
+
+ @Test
+ def concatCharSequenceToStringBuilder: Unit = {
+ val code = """ def charSequence: CharSequence = "def"; def result = "abc" + charSequence """
+ val actualInstructions = instructionsForResultMethod(code)
+ val expectedInstructions = instructionsWithCommonParts(List(Invoke(INVOKEVIRTUAL, "C", "charSequence", "()Ljava/lang/CharSequence;", false), Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/CharSequence;)Ljava/lang/StringBuilder;", false)))
+ assertSameCode(actualInstructions, expectedInstructions)
+ }
+
+ @Test
+ def concatIntToStringBuilder: Unit = {
+ val code = """ def int = 123; def result = "abc" + int """
+ val actualInstructions = instructionsForResultMethod(code)
+ val expectedInstructions = instructionsWithCommonParts(List(Invoke(INVOKEVIRTUAL, "C", "int", "()I", false), Invoke(INVOKESTATIC, "scala/runtime/BoxesRunTime", "boxToInteger", "(I)Ljava/lang/Integer;", false), Invoke(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false)))
+ assertSameCode(actualInstructions, expectedInstructions)
+ }
+}
diff --git a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
index 4d345ab9f7..3fc3144eb2 100644
--- a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
+++ b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
@@ -121,7 +121,7 @@ class PatmatBytecodeTest extends ClearAfterClass {
val code =
"""case class Foo(x: Any, y: String)
|class C {
- | def a = Foo(1, "a") match {
+ | def a = (Foo(1, "a"): @unchecked) match {
| case Foo(_: String, y) => y
| }
|}
diff --git a/test/scaladoc/resources/SI-9599.scala b/test/scaladoc/resources/SI-9599.scala
new file mode 100644
index 0000000000..9365243ffb
--- /dev/null
+++ b/test/scaladoc/resources/SI-9599.scala
@@ -0,0 +1,6 @@
+/**
+ * @todo todo1
+ * @todo todo2
+ * @todo todo3
+ */
+class X
diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.scala b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
index 913667b79b..f0f106b293 100644
--- a/test/scaladoc/scalacheck/HtmlFactoryTest.scala
+++ b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
@@ -819,4 +819,11 @@ object Test extends Properties("HtmlFactory") {
}
}
+
+ property("SI-9599 Multiple @todo formatted with comma on separate line") = {
+ createTemplates("SI-9599.scala")("X.html") match {
+ case node: scala.xml.Node => node.text.contains("todo3todo2todo1")
+ case _ => false
+ }
+ }
}