summaryrefslogtreecommitdiff
path: root/test/files/pos/t9855b.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-07-12 19:45:32 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-07-14 09:14:39 +1000
commitd386e802d53ab616a8a6005c89a9be30ab5526d8 (patch)
treee2600df7327c4a6ed564390f270cac41ace9ebcd /test/files/pos/t9855b.scala
parent4e564efb04e508ccc0f479cf1a25331501927d88 (diff)
downloadscala-d386e802d53ab616a8a6005c89a9be30ab5526d8.tar.gz
scala-d386e802d53ab616a8a6005c89a9be30ab5526d8.tar.bz2
scala-d386e802d53ab616a8a6005c89a9be30ab5526d8.zip
SI-9855 Fix regression in extractor pattern translation
In faa5ae6, I changed the pattern matchers code generator to use stable references (`Ident`-s with the singleton type, rather than the widened type) to the synthetic vals used to store intermediate results ("binders"). In the case where the scrutinee matched the unapply parameter type of some extractor pattern, but the pattern subsequently failed, this led to an regression. It turns out that this was due to the way that the type of the binder was mutated to upcast to the exact type of a subsequent pattern in `ensureConformsTo`: https://github.com/scala/scala/blob/953559988/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala#L165-L174 This was added in 32c57329a as a workaround for the problem caused in t6664.scala, when the binder type was `KList with KCons`, and the code generator wasn't able to find the case field accessors for `KCons` in the decls. The change to use stable references meant that this mutation was now observed in another part of the tree, as opposed to the 2.11.8 situation, where we had used the original, sharper type of the binder eagerly to assign to the `Ident` that referred to it. This led to a tree: Assign(Ident(x3), Ident(x1).setType(x1.tpe) Now that we instead refer generate: Assign(Ident(x3), Ident(x1).setType(stableTypeFor(x1)) and we don't typecheck this until after the mutation of `x1.symbol.info`, we can get a type error. This commit removes this mutation of the binder type altogether, and instead uses `aligner.wholeType`, which is based on the result type of the `Apply(TypeTree(MethodType(params, resultType))` that encodes a typechecked constructor pattern. In `t6624.scala`, this is `KCons`, the case class that has the extractors as its decls.
Diffstat (limited to 'test/files/pos/t9855b.scala')
-rw-r--r--test/files/pos/t9855b.scala16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/files/pos/t9855b.scala b/test/files/pos/t9855b.scala
new file mode 100644
index 0000000000..30c58be3dc
--- /dev/null
+++ b/test/files/pos/t9855b.scala
@@ -0,0 +1,16 @@
+object Test {
+ var FALSE = false
+ def main(args: Array[String]): Unit = {
+ val SomeB = new B
+ new B() match {
+ case SomeB if FALSE =>
+ case SomeB =>
+ case Ext(_) =>
+ }
+ }
+}
+object Ext {
+ def unapply(s: A) = Some(())
+}
+class A
+class B extends A