summaryrefslogtreecommitdiff
path: root/test/pending
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-02-12 14:41:36 +0100
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-02-12 20:54:47 -0800
commitc956a27c3278b99d45676c268955a9e58a1ed15c (patch)
tree0c30690c97b32232398f0ae36fa059ccc835d84d /test/pending
parentb4e1a308f81d48b72ba90b7a8594759f27e1d8f3 (diff)
downloadscala-c956a27c3278b99d45676c268955a9e58a1ed15c.tar.gz
scala-c956a27c3278b99d45676c268955a9e58a1ed15c.tar.bz2
scala-c956a27c3278b99d45676c268955a9e58a1ed15c.zip
SI-5900 Fix pattern inference regression
This commit does not close SI-5900. It only addresses a regression in 2.11 prereleases caused by SI-7886. The fix for SI-7886 was incomplete (as shown by the last commit) and incorrect (as shown by the regression in pos/t5900a.scala and the fact it ended up inferring type parameters.) I believe that the key to fixing this problem will be unifying the inference of case class constructor patterns and extractor patterns. I've explored that idea: https://gist.github.com/retronym/7704153 https://github.com/retronym/scala/compare/ticket/5900 But didn't quite get there.
Diffstat (limited to 'test/pending')
-rw-r--r--test/pending/neg/t7886.scala22
-rw-r--r--test/pending/pos/pattern-typing.scala29
2 files changed, 51 insertions, 0 deletions
diff --git a/test/pending/neg/t7886.scala b/test/pending/neg/t7886.scala
new file mode 100644
index 0000000000..55d80a0a43
--- /dev/null
+++ b/test/pending/neg/t7886.scala
@@ -0,0 +1,22 @@
+trait Covariant[+A]
+trait Contra[-A] { def accept(p: A): Unit }
+trait Invariant[A] extends Covariant[A] with Contra[A]
+
+case class Unravel[A](m: Contra[A], msg: A)
+
+object Test extends Covariant[Any] {
+ def g(m: Contra[Any]): Unit = m accept 5
+ def f(x: Any): Unit = x match {
+ case Unravel(m, msg) => g(m)
+ case _ =>
+ }
+ def main(args: Array[String]) {
+ f(Unravel[String](new Contra[String] { def accept(x: String) = x.length }, ""))
+ }
+}
+// java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
+// at Test$$anon$1.accept(a.scala:18)
+// at Test$.g(a.scala:13)
+// at Test$.f(a.scala:15)
+// at Test$.main(a.scala:18)
+// at Test.main(a.scala)
diff --git a/test/pending/pos/pattern-typing.scala b/test/pending/pos/pattern-typing.scala
new file mode 100644
index 0000000000..7286cc38af
--- /dev/null
+++ b/test/pending/pos/pattern-typing.scala
@@ -0,0 +1,29 @@
+import scala.language.higherKinds
+
+trait Bound[B]
+
+package p1 {
+ case class Sub[B <: Bound[B]](p: B)
+ object Test {
+ def g[A](x: Bound[A]) = ()
+ def f(x: Any) = x match { case Sub(p) => g(p) }
+ }
+}
+
+package p2 {
+ trait Traversable[+A] { def head: A = ??? }
+ trait Seq[+A] extends Traversable[A] { def length: Int = ??? }
+
+ case class SubHK[B <: Bound[B], CC[X] <: Traversable[X]](xs: CC[B])
+ class MyBound extends Bound[MyBound]
+ class MySeq extends Seq[MyBound]
+
+ object Test {
+ def g[B](x: Bound[B]) = ()
+
+ def f1(x: Any) = x match { case SubHK(xs) => xs }
+ def f2[B <: Bound[B], CC[X] <: Traversable[X]](sub: SubHK[B, CC]): CC[B] = sub match { case SubHK(xs) => xs }
+ def f3 = g(f1(SubHK(new MySeq)).head)
+ def f4 = g(f2(SubHK(new MySeq)).head)
+ }
+}