summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-01-14 15:29:51 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-01-14 15:29:51 -0800
commit1a305a5aa8aae2a6d196918664c0c4a9cf808687 (patch)
treefa9f909cc3eb892e933a59278644820f6d419537
parentc20060b956edf7f3a6b427553708f4017bdf0fe0 (diff)
parent8fb19b132579b7ddb9dd12ae829451dcf9d91332 (diff)
downloadscala-1a305a5aa8aae2a6d196918664c0c4a9cf808687.tar.gz
scala-1a305a5aa8aae2a6d196918664c0c4a9cf808687.tar.bz2
scala-1a305a5aa8aae2a6d196918664c0c4a9cf808687.zip
Merge pull request #1876 from adriaanm/ticket-5189-inf
SI-5189 detect unsoundness when inferring type of match
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala11
-rw-r--r--test/files/neg/t5189_inferred.check6
-rw-r--r--test/files/neg/t5189_inferred.scala8
3 files changed, 19 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index e3fd83f388..979c0f59f4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2552,11 +2552,7 @@ trait Typers extends Modes with Adaptations with Tags {
}
// body1 = checkNoEscaping.locals(context.scope, pt, body1)
- val treeWithSkolems = treeCopy.CaseDef(cdef, pat1, guard1, body1) setType body1.tpe
-
- new TypeMapTreeSubstituter(deskolemizeGADTSkolems).traverse(treeWithSkolems)
-
- treeWithSkolems // now without skolems, actually
+ treeCopy.CaseDef(cdef, pat1, guard1, body1) setType body1.tpe
}
// undo adaptConstrPattern's evil deeds, as they confuse the old pattern matcher
@@ -2591,7 +2587,10 @@ trait Typers extends Modes with Adaptations with Tags {
val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, resTp))
- treeCopy.Match(tree, selector1, casesAdapted) setType resTp
+ val matchTyped = treeCopy.Match(tree, selector1, casesAdapted) setType resTp
+ if (!newPatternMatching) // TODO: remove this in 2.11 -- only needed for old pattern matcher
+ new TypeMapTreeSubstituter(deskolemizeGADTSkolems).traverse(matchTyped)
+ matchTyped
}
// match has been typed -- virtualize it if we're feeling experimental
diff --git a/test/files/neg/t5189_inferred.check b/test/files/neg/t5189_inferred.check
new file mode 100644
index 0000000000..9cc5dcc242
--- /dev/null
+++ b/test/files/neg/t5189_inferred.check
@@ -0,0 +1,6 @@
+t5189_inferred.scala:7: error: type mismatch;
+ found : scala.collection.immutable.Nil.type
+ required: ?A1 where type ?A1
+ f(Invariant(arr): Covariant[Any])(0) = Nil
+ ^
+one error found
diff --git a/test/files/neg/t5189_inferred.scala b/test/files/neg/t5189_inferred.scala
new file mode 100644
index 0000000000..e4e8765445
--- /dev/null
+++ b/test/files/neg/t5189_inferred.scala
@@ -0,0 +1,8 @@
+trait Covariant[+A]
+case class Invariant[A](xs: Array[A]) extends Covariant[A]
+
+class Test {
+ val arr = Array("abc")
+ def f[A](v: Covariant[A]) /*inferred!*/ = v match { case Invariant(xs) => xs }
+ f(Invariant(arr): Covariant[Any])(0) = Nil
+} \ No newline at end of file