From 1cd7a9e840158dab17a3aafc0ce849605706a561 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 17 Aug 2013 09:58:54 -0700 Subject: New tests for name-based pattern matcher. --- test/pending/neg/t6680a.scala | 13 +++++++++++++ test/pending/neg/t6680b.check | 6 ++++++ test/pending/neg/t6680b.scala | 10 ++++++++++ test/pending/neg/t6680c.scala | 17 +++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 test/pending/neg/t6680a.scala create mode 100644 test/pending/neg/t6680b.check create mode 100644 test/pending/neg/t6680b.scala create mode 100644 test/pending/neg/t6680c.scala (limited to 'test/pending') diff --git a/test/pending/neg/t6680a.scala b/test/pending/neg/t6680a.scala new file mode 100644 index 0000000000..745334b1cd --- /dev/null +++ b/test/pending/neg/t6680a.scala @@ -0,0 +1,13 @@ +case class Cell[A](var x: A) +object Test { + def f1(x: Any) = x match { case y @ Cell(_) => y } // Inferred type is Cell[Any] + // def f2(x: Cell[_]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[_] + // def f3[A](x: Cell[A]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[A] + + def main(args: Array[String]): Unit = { + // val x = new Cell(1) + // val y = f1(x) + // y.x = "abc" + // println(x.x + 1) + } +} \ No newline at end of file diff --git a/test/pending/neg/t6680b.check b/test/pending/neg/t6680b.check new file mode 100644 index 0000000000..a16812d91d --- /dev/null +++ b/test/pending/neg/t6680b.check @@ -0,0 +1,6 @@ +t6680b.scala:8: error: type mismatch; + found : String("not what you\'d expect") + required: ?Hidden1 where type ?Hidden1 (this is a GADT skolem) + case Concrete(f) => f("not what you'd expect") + ^ +one error found diff --git a/test/pending/neg/t6680b.scala b/test/pending/neg/t6680b.scala new file mode 100644 index 0000000000..e9f6468315 --- /dev/null +++ b/test/pending/neg/t6680b.scala @@ -0,0 +1,10 @@ +trait Super[+A] +// `Hidden` must occur in both variance positions (covariant/contravariant) for the sneakiness to work +// this way type inference will infer Any for `Hidden` and `A` in the pattern below +case class Concrete[Hidden, +A](havoc: Hidden => Hidden) extends Super[A] + +object Test extends App { + (Concrete((x: Int) => x): Super[Any]) match { + case Concrete(f) => f("not what you'd expect") + } +} \ No newline at end of file diff --git a/test/pending/neg/t6680c.scala b/test/pending/neg/t6680c.scala new file mode 100644 index 0000000000..f69663a71b --- /dev/null +++ b/test/pending/neg/t6680c.scala @@ -0,0 +1,17 @@ +package s + +trait Stream[+A] +case class Unfold[S,+A](s: S, f: S => Option[(A,S)]) extends Stream[A] + +object Stream { + def fromList[A](a: List[A]): Stream[A] = + Unfold(a, (l:List[A]) => l.headOption.map((_,l.tail))) +} + +object Test { + def main(args: Array[String]): Unit = { + val res = Stream.fromList(List(1,2,3,4)) + + res match { case Unfold(s, f) => f("a string!") } + } +} -- cgit v1.2.3