diff options
Diffstat (limited to 'test/files')
35 files changed, 609 insertions, 149 deletions
diff --git a/test/files/neg/t2066.check b/test/files/neg/t2066.check new file mode 100644 index 0000000000..efade87e26 --- /dev/null +++ b/test/files/neg/t2066.check @@ -0,0 +1,21 @@ +t2066.scala:6: error: overriding method f in trait A1 of type [T[_]]=> Unit; + method f has incompatible type + override def f[T[+_]] = () + ^ +t2066.scala:10: error: overriding method f in trait A1 of type [T[_]]=> Unit; + method f has incompatible type + override def f[T[-_]] = () + ^ +t2066.scala:23: error: overriding method f in trait A2 of type [T[+_]]=> Unit; + method f has incompatible type + override def f[T[-_]] = () + ^ +t2066.scala:45: error: overriding method f in trait A4 of type [T[X[+_]]]=> Unit; + method f has incompatible type + override def f[T[X[_]]] = () + ^ +t2066.scala:53: error: overriding method f in trait A5 of type [T[X[-_]]]=> Unit; + method f has incompatible type + override def f[T[X[_]]] = () + ^ +5 errors found diff --git a/test/files/neg/t2066.scala b/test/files/neg/t2066.scala new file mode 100644 index 0000000000..7f15d39c67 --- /dev/null +++ b/test/files/neg/t2066.scala @@ -0,0 +1,70 @@ +trait A1 { + def f[T[_]] = () +} + +trait B1 extends A1 { + override def f[T[+_]] = () +} + +trait C1 extends A1 { + override def f[T[-_]] = () +} + + +trait A2 { + def f[T[+_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () // okay +} + +trait C2 extends A2 { + override def f[T[-_]] = () +} + + +trait A3 { + def f[T[-_]] = () +} + +trait B3 extends A3 { + override def f[T[_]] = () // okay +} + +trait C3 extends A3 { + override def f[T[-_]] = () +} + + +trait A4 { + def f[T[X[+_]]] = () +} + +trait B4 extends A4 { + override def f[T[X[_]]] = () +} + +trait A5 { + def f[T[X[-_]]] = () +} + +trait B5 extends A5 { + override def f[T[X[_]]] = () +} + + + +trait A6 { + def f[T[X[_]]] = () +} + +trait B6 extends A6 { + override def f[T[X[+_]]] = () // okay +} +trait C6 extends A6 { + override def f[T[X[_]]] = () // okay +} +trait D6 extends A6 { + override def f[T[X[-_]]] = () +} diff --git a/test/files/neg/t2066b.check b/test/files/neg/t2066b.check new file mode 100644 index 0000000000..097c44fef3 --- /dev/null +++ b/test/files/neg/t2066b.check @@ -0,0 +1,5 @@ +t2066b.scala:7: error: overriding method f in trait A of type [T[_]](x: T[Int])T[Any]; + method f has incompatible type + def f[T[+_]](x : T[Int]) : T[Any] = x + ^ +one error found diff --git a/test/files/neg/t2066b.scala b/test/files/neg/t2066b.scala new file mode 100644 index 0000000000..46177b19f7 --- /dev/null +++ b/test/files/neg/t2066b.scala @@ -0,0 +1,16 @@ +object Test extends App { + trait A { + def f[T[_]](x : T[Int]) : T[Any] + } + + class B extends A { + def f[T[+_]](x : T[Int]) : T[Any] = x + } + + class P[Y](var y : Y) + + val p = new P(1) + val palias = (new B():A).f[P](p) + palias.y = "hello" + val z: Int = p.y +}
\ No newline at end of file diff --git a/test/files/neg/t4425.check b/test/files/neg/t4425.check index 95b88a6b3d..00006c08f0 100644 --- a/test/files/neg/t4425.check +++ b/test/files/neg/t4425.check @@ -1,12 +1,12 @@ -t4425.scala:3: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:3: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: Int)(y: Option[Int]): None.type exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list 42 match { case _ X _ => () } ^ -t4425.scala:8: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: Int)(y: Int): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list 42 match { case _ X _ => () } ^ -t4425.scala:13: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425.scala:13: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list "" match { case _ X _ => () } ^ diff --git a/test/files/neg/t4425b.check b/test/files/neg/t4425b.check index 1186e8b609..8418b4fd12 100644 --- a/test/files/neg/t4425b.check +++ b/test/files/neg/t4425b.check @@ -1,61 +1,49 @@ -t4425b.scala:5: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:5: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:6: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:6: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:7: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:7: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case X(_) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:8: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:9: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:9: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:10: error: object X is not a case class constructor, nor does it have an unapply/unapplySeq method +t4425b.scala:10: error: object X is not a case class, nor does it have an unapply/unapplySeq member Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:18: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:18: error: too many patterns for object X: expected 1, found 2 println( "" match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:19: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:19: error: too many patterns for object X: expected 1, found 2 println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:22: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:22: error: too many patterns for object X: expected 1, found 2 println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:22: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 - println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) - ^ -t4425b.scala:23: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:23: error: too many patterns for object X: expected 1, found 2 println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:23: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 - println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) - ^ -t4425b.scala:31: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:31: error: too many patterns for object X offering Nothing: expected 1, found 2 println( "" match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:32: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:32: error: too many patterns for object X offering Nothing: expected 1, found 2 println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) ^ -t4425b.scala:35: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:35: error: too many patterns for object X offering Nothing: expected 1, found 2 println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:35: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 - println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) - ^ -t4425b.scala:36: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 +t4425b.scala:36: error: too many patterns for object X offering Nothing: expected 1, found 2 println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) ^ -t4425b.scala:36: error: wrong number of patterns for object X offering Nothing: expected 1, found 2 - println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) - ^ -18 errors found +14 errors found diff --git a/test/files/neg/t5903a.check b/test/files/neg/t5903a.check index 2e5cc87167..34003b0a82 100644 --- a/test/files/neg/t5903a.check +++ b/test/files/neg/t5903a.check @@ -1,4 +1,4 @@ -Test_2.scala:4: error: wrong number of patterns for <$anon: AnyRef> offering (SomeTree.type, SomeTree.type): expected 2, found 3 +Test_2.scala:4: error: too many patterns for <$anon: AnyRef> offering (SomeTree.type, SomeTree.type): expected 2, found 3 case nq"$x + $y + $z" => println((x, y)) ^ one error found diff --git a/test/files/neg/t6675b.check b/test/files/neg/t6675b.check new file mode 100644 index 0000000000..77f6b3ccbc --- /dev/null +++ b/test/files/neg/t6675b.check @@ -0,0 +1,37 @@ +t6675b.scala:17: warning: object LeftOrRight expects 2 patterns to hold (Int, Int) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight(a) => a } // warn + ^ +t6675b.scala:19: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: (Int, Int) + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b, c)) => a } // fail + ^ +t6675b.scala:24: warning: object LeftOrRight expects 2 patterns to hold (A, A) but crushing into 2-tuple to fit single pattern (SI-6675) + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight(a) => a } // warn + ^ +t6675b.scala:26: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: (?A11, ?A12) where type ?A12 <: A (this is a GADT skolem), type ?A11 <: A (this is a GADT skolem) + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b, c)) => a } // fail + ^ +t6675b.scala:30: warning: object NativelyTwo expects 2 patterns to hold ((Int, Int), (Int, Int)) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:32: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: ((Int, Int), (Int, Int)) + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b, c)) => a } // fail + ^ +t6675b.scala:36: warning: object NativelyTwo expects 2 patterns to hold (A, A) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1[A](x: A) = (Left(x): Either[A, A]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:37: warning: object NativelyTwo expects 2 patterns to hold ((A, A), (A, A)) but crushing into 2-tuple to fit single pattern (SI-6675) + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:39: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: ((?A17, ?A18), (?A19, ?A20)) where type ?A20 <: A (this is a GADT skolem), type ?A19 <: A (this is a GADT skolem), type ?A18 <: A (this is a GADT skolem), type ?A17 <: A (this is a GADT skolem) + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b, c)) => a } // fail + ^ +5 warnings found +four errors found diff --git a/test/files/neg/t6675b.flags b/test/files/neg/t6675b.flags new file mode 100644 index 0000000000..1008b0a70c --- /dev/null +++ b/test/files/neg/t6675b.flags @@ -0,0 +1 @@ +-Xlint diff --git a/test/files/neg/t6675b.scala b/test/files/neg/t6675b.scala new file mode 100644 index 0000000000..c86c9c3955 --- /dev/null +++ b/test/files/neg/t6675b.scala @@ -0,0 +1,40 @@ +object LeftOrRight { + def unapply[A](value: Either[A, A]): Option[A] = value match { + case scala.Left(x) => Some(x) + case scala.Right(x) => Some(x) + } +} + +object NativelyTwo { + def unapply[A](value: Either[A, A]): Option[(A, A)] = value match { + case scala.Left(x) => Some(x -> x) + case scala.Right(x) => Some(x -> x) + } +} + + +class A { + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight(a) => a } // warn + def f2 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b)) => a } // no warn + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b, c)) => a } // fail +} + +class B { + def f1[A](x: A) = (Left(x): Either[A, A]) match { case LeftOrRight(a) => a } // no warn + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight(a) => a } // warn + def f3[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b)) => a } // no warn + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b, c)) => a } // fail +} + +class C { + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo(a) => a } // warn + def f2 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b)) => a } // no warn + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b, c)) => a } // fail +} + +class D { + def f1[A](x: A) = (Left(x): Either[A, A]) match { case NativelyTwo(a) => a } // warn + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo(a) => a } // warn + def f3[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b)) => a } // no warn + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b, c)) => a } // fail +} diff --git a/test/files/neg/t7214neg.check b/test/files/neg/t7214neg.check index 0660cccd02..291af04578 100644 --- a/test/files/neg/t7214neg.check +++ b/test/files/neg/t7214neg.check @@ -1,7 +1,4 @@ -t7214neg.scala:28: error: wrong number of patterns for object Extractor offering Any: expected 1, found 0 +t7214neg.scala:28: error: not enough patterns for object Extractor offering Any: expected 1, found 0 case Extractor() => ^ -t7214neg.scala:28: error: wrong number of patterns for object Extractor offering Any: expected 1, found 0 - case Extractor() => - ^ -two errors found +one error found diff --git a/test/files/neg/t7850.check b/test/files/neg/t7850.check new file mode 100644 index 0000000000..317be2bbce --- /dev/null +++ b/test/files/neg/t7850.check @@ -0,0 +1,7 @@ +t7850.scala:11: error: an unapply result must have a member `def isEmpty: Boolean (found: def isEmpty: Casey) + val Casey(x1) = new Casey(1) + ^ +t7850.scala:12: error: an unapply result must have a member `def isEmpty: Boolean + val Dingy(x2) = new Dingy(1) + ^ +two errors found diff --git a/test/files/neg/t7850.scala b/test/files/neg/t7850.scala new file mode 100644 index 0000000000..04edad82b5 --- /dev/null +++ b/test/files/neg/t7850.scala @@ -0,0 +1,16 @@ +// isEmpty returns non-boolean +class Casey(a: Int) { def isEmpty = this; def get = this } +object Casey { def unapply(a: Casey) = a } + +// no isEmpty method at all +class Dingy(a: Int) { def get = this } +object Dingy { def unapply(a: Dingy) = a } + +object Test { + def main(args: Array[String]) { + val Casey(x1) = new Casey(1) + val Dingy(x2) = new Dingy(1) + println(s"$x1 $x2") + } +} + diff --git a/test/files/neg/t7897.check b/test/files/neg/t7897.check new file mode 100644 index 0000000000..48eff511c7 --- /dev/null +++ b/test/files/neg/t7897.check @@ -0,0 +1,4 @@ +t7897.scala:19: error: value length is not a member of p0.Single + case p0.Single(x) => println(s"`$x` has ${x.length} chars") + ^ +one error found diff --git a/test/files/neg/t7897.scala b/test/files/neg/t7897.scala new file mode 100644 index 0000000000..87c966b1e0 --- /dev/null +++ b/test/files/neg/t7897.scala @@ -0,0 +1,23 @@ +package p0 { + class Single(val x: Any) extends AnyRef with Product1[String] { + private def s = "" + x + override def canEqual(x: Any) = this eq x.asInstanceOf[AnyRef] + def isEmpty = false + def get = this + def _1 = s + " only" + + override def toString = s"Single(${_1})" + } + + object Single { + def unapply(x: Any): Single = new Single(x) + } +} +object Test { + def main(args: Array[String]): Unit = { + "catdog" match { + case p0.Single(x) => println(s"`$x` has ${x.length} chars") + case x => println("fail: " + x) + } + } +} diff --git a/test/files/neg/t997.check b/test/files/neg/t997.check index 8c41060ba2..b118792229 100644 --- a/test/files/neg/t997.check +++ b/test/files/neg/t997.check @@ -1,7 +1,4 @@ -t997.scala:13: error: wrong number of patterns for object Foo offering (String, String): expected 2, found 3 +t997.scala:13: error: too many patterns for object Foo offering (String, String): expected 2, found 3 "x" match { case Foo(a, b, c) => Console.println((a,b,c)) } ^ -t997.scala:13: error: wrong number of patterns for object Foo offering (String, String): expected 2, found 3 -"x" match { case Foo(a, b, c) => Console.println((a,b,c)) } - ^ -two errors found +one error found diff --git a/test/files/pos/t2066.scala b/test/files/pos/t2066.scala new file mode 100644 index 0000000000..30cb99d45c --- /dev/null +++ b/test/files/pos/t2066.scala @@ -0,0 +1,25 @@ +trait A1 { + def f[T[+_]] = () +} + +trait B1 extends A1 { + override def f[T[_]] = () +} + + +trait A2 { + def f[T[-_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () +} + + +trait A3 { + def f[T[X[_]]] = () +} + +trait B3 extends A3 { + override def f[T[X[+_]]] = () +} diff --git a/test/files/pos/t8045.scala b/test/files/pos/t8045.scala new file mode 100644 index 0000000000..21154e386a --- /dev/null +++ b/test/files/pos/t8045.scala @@ -0,0 +1,17 @@ +object Test extends App { + case class Number(i: Int) + + object UnliftNumber { + def unapply(t: Any): Option[Number] = t match { + case i: Int => Some(Number(i)) + case _ => None + } + } + + def eval(expr: Any): Option[Number] = expr match { + case UnliftNumber(n) => Some(n) + case _ => None + } + + println(eval(1)) +} diff --git a/test/files/pos/t8046.scala b/test/files/pos/t8046.scala new file mode 100644 index 0000000000..304d70b6b8 --- /dev/null +++ b/test/files/pos/t8046.scala @@ -0,0 +1,20 @@ +trait One { + type Op[A] + type Alias[A] = Op[A] +} + +trait Two extends One { + trait Op[A] extends (A => A) + + // This compiles + class View1 extends Op[Int] { def apply(xs: Int) = xs } + + // ??? base class View2 not found in basetypes of class View2 + // ./a.scala:9: error: class View2 needs to be abstract, since \ + // method apply in trait Function1 of type (v1: T1)R is not defined + // (Note that T1 does not match Int) + // class View2 extends Alias[Int] { def apply(xs: Int) = xs } + // ^ + // one error found + class View2 extends Alias[Int] { def apply(xs: Int) = xs } +} diff --git a/test/files/pos/t8046b.scala b/test/files/pos/t8046b.scala new file mode 100644 index 0000000000..45b99fd7e0 --- /dev/null +++ b/test/files/pos/t8046b.scala @@ -0,0 +1,16 @@ +trait One { + type Op[A] + type Alias = Op[Int] +} + +trait Two extends One { + trait Op[A] extends M[A] + //(a: Alias) => a.value.toChar // okay + // (=> A).asSeenFrom(a.type, trait M): => Int + class View2 extends Alias { value.toChar } // toChar is not a member of type parameter A + // (=> A).asSeenFrom(View2.this.type, trait M): => A + + // override type Alias = Op[Int] // works with this +} + +trait M[A] { def value: A = sys.error("") } diff --git a/test/files/pos/t8046c.scala b/test/files/pos/t8046c.scala new file mode 100644 index 0000000000..f05b4c15b5 --- /dev/null +++ b/test/files/pos/t8046c.scala @@ -0,0 +1,19 @@ +trait One { + type Op[A] + type Alias[A] = Op[A] +} + +trait Three extends One { + trait Op[A] extends (A => A) + + def f1(f: Op[Int]) = f(5) + def f2(f: Alias[Int]) = f(5) + def f3[T <: Op[Int]](f: T) = f(5) + def f4[T <: Alias[Int]](f: T) = f(5) + // ./a.scala:12: error: type mismatch; + // found : Int(5) + // required: T1 + // def f4[T <: Alias[Int]](f: T) = f(5) + // ^ +} + diff --git a/test/files/pos/t8128.scala b/test/files/pos/t8128.scala new file mode 100644 index 0000000000..b6f76691b0 --- /dev/null +++ b/test/files/pos/t8128.scala @@ -0,0 +1,15 @@ +object G { + def unapply(m: Any): Option[_] = Some("") +} + +object H { + def unapplySeq(m: Any): Option[Seq[_]] = None +} + +object Test { + (0: Any) match { + case G(v) => v + case H(v) => v + case _ => + } +} diff --git a/test/files/presentation/context-bounds1.check b/test/files/presentation/context-bounds1.check deleted file mode 100644 index b444de59a4..0000000000 --- a/test/files/presentation/context-bounds1.check +++ /dev/null @@ -1,51 +0,0 @@ -reload: ContextBounds.scala - -askHyperlinkPos for `Blubb` at (2,23) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `Blubb` at (13,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `Foo` at (4,17) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `Foo` at (9,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `Blubb` at (4,32) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `Blubb` at (13,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `A` at (4,42) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `A` at (4,12) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `A` at (4,51) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `A` at (4,12) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `blubb` at (4,66) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `blubb` at (2,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `Foo` at (5,18) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `Foo` at (9,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `A` at (5,25) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `A` at (4,12) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `foo` at (5,36) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `foo` at (10,7) ContextBounds.scala -================================================================================ - -askHyperlinkPos for `A` at (10,14) ContextBounds.scala -================================================================================ -[response] found askHyperlinkPos for `A` at (9,11) ContextBounds.scala -================================================================================ diff --git a/test/files/presentation/context-bounds1/Test.scala b/test/files/presentation/context-bounds1/Test.scala deleted file mode 100644 index bec1131c4c..0000000000 --- a/test/files/presentation/context-bounds1/Test.scala +++ /dev/null @@ -1,3 +0,0 @@ -import scala.tools.nsc.interactive.tests.InteractiveTest - -object Test extends InteractiveTest
\ No newline at end of file diff --git a/test/files/presentation/context-bounds1/src/ContextBounds.scala b/test/files/presentation/context-bounds1/src/ContextBounds.scala deleted file mode 100644 index 72a8f694a3..0000000000 --- a/test/files/presentation/context-bounds1/src/ContextBounds.scala +++ /dev/null @@ -1,13 +0,0 @@ -object ContextBound { - val blubb = new Blubb/*#*/ - - def work[A: Foo/*#*/](f: Blubb/*#*/ => A/*#*/): A/*#*/ = f(blubb/*#*/) ensuring { - implicitly[Foo/*#*/[A/*#*/]].foo/*#*/(_) >= 42 - } -} - -trait Foo[A] { - def foo(a: A/*#*/): Int -} - -class Blubb
\ No newline at end of file diff --git a/test/files/run/macroPlugins-namerHooks.scala b/test/files/run/macroPlugins-namerHooks.scala index a71d685f7f..302429b19e 100644 --- a/test/files/run/macroPlugins-namerHooks.scala +++ b/test/files/run/macroPlugins-namerHooks.scala @@ -14,19 +14,20 @@ object Test extends DirectTest { import analyzer._ val output = collection.mutable.ListBuffer[String]() + def log(what: String) = output += what.replace(String.format("%n"), " ") object macroPlugin extends MacroPlugin { override def pluginsEnterSym(namer: Namer, tree: Tree): Boolean = { - output += s"enterSym(${tree.toString.replace('\n', ' ')})" + log(s"enterSym($tree)") namer.standardEnterSym(tree) true } override def pluginsEnsureCompanionObject(namer: Namer, cdef: ClassDef, creator: ClassDef => Tree = companionModuleDef(_)): Option[Symbol] = { - output += s"ensureCompanionObject(${cdef.toString.replace('\n', ' ')}, ...)" + log(s"ensureCompanionObject($cdef, ...)") Some(namer.standardEnsureCompanionObject(cdef, creator)) } override def pluginsEnterStats(typer: Typer, stats: List[Tree]): List[Tree] = { - stats.foreach(stat => output += s"enterStat(${stat.toString.replace('\n', ' ')})") + stats.foreach(stat => log(s"enterStat($stat)")) stats } } diff --git a/test/files/run/name-based-patmat.check b/test/files/run/name-based-patmat.check index 1cc605ea3d..3d5fc40ed7 100644 --- a/test/files/run/name-based-patmat.check +++ b/test/files/run/name-based-patmat.check @@ -1,3 +1,5 @@ +`catdog only` has 11 chars +`catdog only, no product` has 23 chars catdog 2 catdogs! A ha ha! 3 catdogs! A ha ha! diff --git a/test/files/run/name-based-patmat.scala b/test/files/run/name-based-patmat.scala index 2c429c141f..8e20940100 100644 --- a/test/files/run/name-based-patmat.scala +++ b/test/files/run/name-based-patmat.scala @@ -1,5 +1,33 @@ final class MiniSome[T](val get: T) extends AnyVal { def isEmpty = false } +package p0 { + class Single(val x: Any) extends AnyRef with Product1[String] { + private def s = "" + x + override def canEqual(x: Any) = this eq x.asInstanceOf[AnyRef] + def isEmpty = false + def get = this + def _1 = s + " only" + + override def toString = s"Single(${_1})" + } + + object Single { + def unapply(x: Any): Single = new Single(x) + } + + class SingleNoProduct(val x: Any) extends AnyRef { + private def s = "" + x + def isEmpty = false + def get = s + " only, no product" + + override def toString = s"SingleNoProduct($get)" + } + + object SingleNoProduct { + def unapply(x: Any): SingleNoProduct = new SingleNoProduct(x) + } +} + package p1 { class Triple(val x: Any) extends AnyRef with Product3[String, String, String] { private def s = "" + x @@ -49,14 +77,16 @@ package p3 { } object Test { - - // def f(x: Any) = x match { - // case p1.Foo(x, y, z) => println((x, y, z)) - // case x => println(x) - // } - def main(args: Array[String]): Unit = { "catdog" match { + case p0.Single(x) => println(s"`${x._1}` has ${x._1.length} chars") + case x => println("fail: " + x) + } + "catdog" match { + case p0.SingleNoProduct(x) => println(s"`$x` has ${x.length} chars") + case x => println("fail: " + x) + } + "catdog" match { case p1.Triple(x, y, z) => List(x, y, z) foreach println case x => println("fail: " + x) } diff --git a/test/files/run/patmat-mix-case-extractor.check b/test/files/run/patmat-mix-case-extractor.check new file mode 100644 index 0000000000..a6e1bd23df --- /dev/null +++ b/test/files/run/patmat-mix-case-extractor.check @@ -0,0 +1,8 @@ +-1 +6 +4 +18 +-1 +1006 +1004 +1018 diff --git a/test/files/run/patmat-mix-case-extractor.scala b/test/files/run/patmat-mix-case-extractor.scala new file mode 100644 index 0000000000..964e6f743c --- /dev/null +++ b/test/files/run/patmat-mix-case-extractor.scala @@ -0,0 +1,110 @@ +trait CaseClass +trait ProdCaseClass extends CaseClass { def x: Int } +trait SeqCaseClass extends CaseClass { def xs: Seq[Int] } + +case class CaseClass1() extends CaseClass +case class CaseClass2(xs: Int*) extends SeqCaseClass +case class CaseClass3(x: Int) extends ProdCaseClass +case class CaseClass4(x: Int, xs: Int*) extends ProdCaseClass with SeqCaseClass + +object Extractor1 { def unapply(x: CaseClass): Boolean = false } +object Extractor2 { def unapplySeq(x: SeqCaseClass): Option[Seq[Int]] = Some(x.xs) } +object Extractor3 { def unapply(x: ProdCaseClass): Option[Int] = Some(x.x) } +object Extractor4 { def unapplySeq(x: ProdCaseClass with SeqCaseClass): Option[(Int, Seq[Int])] = Some(x.x, x.xs) } + +class A { + def f1(x: Any) = x match { + case CaseClass1() => -1 + case CaseClass2(xs @ _*) => xs.sum + case CaseClass3(x) => x + case CaseClass4(x, xs @ _*) => x + xs.sum + case Extractor4(x, xs @ _*) => 1000 + x + xs.sum + case Extractor3(x) => 1000 + x + case Extractor2(xs @ _*) => 1000 + xs.sum + case Extractor1() => -3 + case _ => -2 + } + def f2(x: Any) = x match { + case Extractor4(x, xs @ _*) => 1000 + x + xs.sum + case Extractor3(x) => 1000 + x + case Extractor2(xs @ _*) => 1000 + xs.sum + case Extractor1() => -3 + case CaseClass1() => -1 + case CaseClass2(xs @ _*) => xs.sum + case CaseClass3(x) => x + case CaseClass4(x, xs @ _*) => x + xs.sum + case _ => -2 + } + def run() { + List( + f1(CaseClass1()), + f1(CaseClass2(1, 2, 3)), + f1(CaseClass3(4)), + f1(CaseClass4(5, 6, 7)), + f2(CaseClass1()), + f2(CaseClass2(1, 2, 3)), + f2(CaseClass3(4)), + f2(CaseClass4(5, 6, 7)) + ) foreach println + } +} + +object Test { + def main(args: Array[String]): Unit = { + (new A).run + } +} + + +class B { + case class CaseClass0() + case class CaseClass0v(xs: Int*) + + case class CaseClass(x: Int, y: Int) + object Extractor { def unapply(x: Any): Option[(Int, Int)] = Some((1, 1)) } + + case class CaseSeq(x: Char, y: Double, zs: Int*) + object ExtractorSeq { def unapplySeq(x: Any): Option[(Int, Int, Seq[Int])] = Some((1, 1, List(1))) } + + def f1(x: CaseClass) = x match { case CaseClass(y, z) => y } + def f2(x: Any) = x match { case Extractor(y, z) => y } + + def f3(x: CaseSeq) = x match { + case CaseSeq(x, y) => y + case CaseSeq(x, y, z) => z + } + def f4(x: CaseSeq) = x match { + case CaseSeq(x, y, z) => z :: Nil + case CaseSeq(x, y, z @ _*) => z + } + + def f5(x: Any) = x match { case ExtractorSeq(x, y, z) => z } + def f6(x: Any) = x match { case ExtractorSeq(x, y, z @ _*) => z } + + def g1(x: CaseClass0) = x match { + case CaseClass0() => true + } + def g2(x: CaseClass0v) = x match { + case CaseClass0v() => true + case CaseClass0v(5) => true + case CaseClass0v(x) => true + case CaseClass0v(xs @ _*) => false + } +} + +package p1 { + trait _X { + case class _Foo(); + object _Bar { + def unapply(foo: _Foo): Boolean = true; + } + } + + object Y extends _X { + val foo = _Foo() + foo match { + case _Bar() => + case _ => assert(false) + } + } +} diff --git a/test/files/run/reflection-sync-potpourri.scala b/test/files/run/reflection-sync-potpourri.scala deleted file mode 100644 index 0ad5f2ab66..0000000000 --- a/test/files/run/reflection-sync-potpourri.scala +++ /dev/null @@ -1,32 +0,0 @@ -import scala.reflect.runtime.universe._ - -// this test checks that under heavily multithreaded conditions: -// 1) scala.reflect.runtime.universe, its rootMirror and definitions are initialized correctly -// 2) symbols are correctly materialized into PackageScopes (no dupes) -// 3) unpickling works okay even we unpickle the same symbol a lot of times - -object Test extends App { - def foo[T: TypeTag](x: T) = typeOf[T].toString - val n = 1000 - val rng = new scala.util.Random() - val types = List( - () => typeOf[java.lang.reflect.Method], - () => typeOf[java.lang.annotation.Annotation], - () => typeOf[scala.io.BufferedSource], - () => typeOf[scala.io.Codec]) - val perms = types.permutations.toList - def force(lazytpe: () => Type): String = { - lazytpe().typeSymbol.typeSignature - lazytpe().toString - } - val diceRolls = List.fill(n)(rng.nextInt(perms.length)) - val threads = (1 to n) map (i => new Thread(s"Reflector-$i") { - override def run(): Unit = { - val s1 = foo("42") - val s2 = perms(diceRolls(i - 1)).map(x => force(x)).sorted.mkString(", ") - assert(s1 == "java.lang.String") - assert(s2 == "java.lang.annotation.Annotation, java.lang.reflect.Method, scala.io.BufferedSource, scala.io.Codec") - } - }) - threads foreach (_.start) -}
\ No newline at end of file diff --git a/test/files/run/t8046.check b/test/files/run/t8046.check new file mode 100644 index 0000000000..905b0b35ca --- /dev/null +++ b/test/files/run/t8046.check @@ -0,0 +1,2 @@ +List(trait Op, trait Function1, class Object, class Any) +BTS(T,Three.this.Op[Int],Int => Int,Object,Any) diff --git a/test/files/run/t8046/Test.scala b/test/files/run/t8046/Test.scala new file mode 100644 index 0000000000..f6b525d1b5 --- /dev/null +++ b/test/files/run/t8046/Test.scala @@ -0,0 +1,18 @@ +import scala.tools.partest._ + +object Test extends DirectTest { + override def code = "" + override def extraSettings: String = "-usejavacp" + + override def show() { + val c = newCompiler() + new c.Run + import c._ + + val f4 = typeOf[Three].member(newTermName("f4")) + val f4ParamInfo = f4.paramss.head.head.info + println(f4ParamInfo.baseClasses) + println(f4ParamInfo.baseTypeSeq) + } +} + diff --git a/test/files/run/t8046/t8046c.scala b/test/files/run/t8046/t8046c.scala new file mode 100644 index 0000000000..0b484da530 --- /dev/null +++ b/test/files/run/t8046/t8046c.scala @@ -0,0 +1,13 @@ +import language._ + +trait One { + type Op[A] + type Alias[A] = Op[A] +} + +trait Three extends One { + trait Op[A] extends (A => A) + + def f4[T <: Alias[Int]](f: T) = 0 +} + diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index 6c7c32bfdf..1eb186f303 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -127,6 +127,47 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { (visited == expectedSize(r)) :| str(r) } + property("sum") = forAll(myGen) { r => +// println("----------") +// println("sum "+str(r)) + val rSum = r.sum + val expected = r.length match { + case 0 => 0 + case 1 => r.head + case _ => ((r.head + r.last).toLong * r.length / 2).toInt + } +// println("size: " + r.length) +// println("expected: " + expected) +// println("obtained: " + rSum) + + (rSum == expected) :| str(r) + } + +/* checks that sum respects custom Numeric */ + property("sumCustomNumeric") = forAll(myGen) { r => + val mod = 65536 + object mynum extends Numeric[Int] { + def plus(x: Int, y: Int): Int = (x + y) % mod + override def zero = 0 + + def fromInt(x: Int): Int = ??? + def minus(x: Int, y: Int): Int = ??? + def negate(x: Int): Int = ??? + def times(x: Int, y: Int): Int = ??? + def toDouble(x: Int): Double = ??? + def toFloat(x: Int): Float = ??? + def toInt(x: Int): Int = ((x % mod) + mod * 2) % mod + def toLong(x: Int): Long = ??? + def compare(x: Int, y: Int): Int = ??? + } + + val rSum = r.sum(mynum) + val expected = mynum.toInt(r.sum) + + (rSum == expected) :| str(r) + } + + property("length") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => // println("length "+str(r)) (r.length == expectedSize(r)) :| str(r) |