summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-03-12 14:29:59 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-03-12 14:46:39 +0100
commit5ef842ec09b58208ab30ffb2b6773b95099b07e7 (patch)
treed7e2da5b61c71aa11181b790801f715015d03c22
parent0fbd4422b2030bd7ec6299d99cac2eaf9a4a0ea9 (diff)
downloadscala-5ef842ec09b58208ab30ffb2b6773b95099b07e7.tar.gz
scala-5ef842ec09b58208ab30ffb2b6773b95099b07e7.tar.bz2
scala-5ef842ec09b58208ab30ffb2b6773b95099b07e7.zip
SI-8395 Regression in pattern matching with nested binds
Regressed in https://github.com/scala/scala/pull/2848. In particular, see 0cf47bdb5b and 017460e63c. Because of the regression, this pattern: (s @ (_s @ (_: String))) was translated into `typeTestStep`, rather than a `bindingStep`. This came down the the use of `unbind` in the `TypeBound` extractor. My first step was to remove the `unbind`. That led to another problem: the tree now matches `SymbolAndTypeBound`, which extracted `symbol = s, tpe = String`, ignoring the `_s`. I changed that extractor to no longer recursively apply to the sub-pattern tree, which is what `MaybeTypedBound` used to do. I also checked for other uses of `unbind` in the match translation. The only place I found it is in `BoundTree#pt`. I believe that this usage is correct, or at least, not obviously incorrect.
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala8
-rw-r--r--test/files/run/t8395.scala9
2 files changed, 13 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
index 699e98f963..4cf8980689 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -81,14 +81,14 @@ trait MatchTranslation {
object SymbolAndTypeBound {
def unapply(tree: Tree): Option[(Symbol, Type)] = tree match {
- case SymbolBound(sym, SymbolAndTypeBound(_, tpe)) => Some(sym -> tpe)
- case TypeBound(tpe) => Some(binder -> tpe)
- case _ => None
+ case SymbolBound(sym, TypeBound(tpe)) => Some(sym -> tpe)
+ case TypeBound(tpe) => Some(binder -> tpe)
+ case _ => None
}
}
object TypeBound {
- def unapply(tree: Tree): Option[Type] = unbind(tree) match {
+ def unapply(tree: Tree): Option[Type] = tree match {
case Typed(Ident(_), _) if tree.tpe != null => Some(tree.tpe)
case _ => None
}
diff --git a/test/files/run/t8395.scala b/test/files/run/t8395.scala
new file mode 100644
index 0000000000..2570550619
--- /dev/null
+++ b/test/files/run/t8395.scala
@@ -0,0 +1,9 @@
+ object Test {
+ def baz(x: Object) = {
+ val s @ (_s: String) = x
+ x
+ }
+ def main(args: Array[String]) {
+ assert(baz("1") == "1")
+ }
+}