summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-08-17 07:44:50 -0700
committerPaul Phillips <paulp@improving.org>2013-08-17 10:58:11 -0700
commit0cf47bdb5b1b57589883544933af56a4af848492 (patch)
treeaa58f51ba86bdde7241ed42bd317bf4638cc000e /src/compiler
parentd351a1f79b5bd5f3be7d5e292f046495a9a0e629 (diff)
downloadscala-0cf47bdb5b1b57589883544933af56a4af848492.tar.gz
scala-0cf47bdb5b1b57589883544933af56a4af848492.tar.bz2
scala-0cf47bdb5b1b57589883544933af56a4af848492.zip
Simplified the MaybeBoundTyped extractor a bit.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
index 2de9dac54f..41bdfe1076 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -293,18 +293,26 @@ trait MatchTranslation extends CpsPatternHacks {
object MaybeBoundTyped {
+ object NonNullTyped {
+ // the Ident subpattern can be ignored, subpatBinder or patBinder tell us all we need to know about it
+ def unapply(tree: Typed): Option[Type] = tree match {
+ case Typed(Ident(_), _) if tree.tpe != null => Some((tree.tpe))
+ case _ => None
+ }
+ }
+
/** Decompose the pattern in `tree`, of shape C(p_1, ..., p_N), into a list of N symbols, and a list of its N sub-trees
* The list of N symbols contains symbols for every bound name as well as the un-named sub-patterns (fresh symbols are generated here for these).
* The returned type is the one inferred by inferTypedPattern (`owntype`)
*
- * @arg patBinder symbol used to refer to the result of the previous pattern's extractor (will later be replaced by the outer tree with the correct tree to refer to that patterns result)
+ * @arg patBinder symbol used to refer to the result of the previous pattern's extractor
+ * (will later be replaced by the outer tree with the correct tree to refer to that patterns result)
*/
def unapply(tree: Tree): Option[(Symbol, Type)] = tree match {
- // the Ident subpattern can be ignored, subpatBinder or patBinder tell us all we need to know about it
- case Bound(subpatBinder, typed@Typed(Ident(_), tpt)) if typed.tpe ne null => Some((subpatBinder, typed.tpe))
- case Bind(_, typed@Typed(Ident(_), tpt)) if typed.tpe ne null => Some((patBinder, typed.tpe))
- case Typed(Ident(_), tpt) if tree.tpe ne null => Some((patBinder, tree.tpe))
- case _ => None
+ case Bound(binder, MaybeBoundTyped(_, tpe)) => Some((binder, tpe)) // possible nested bindings - use the outermost
+ case NonNullTyped(tpe) => Some((patBinder, tpe)) // patBinder used if no local bindings
+ case Bind(_, expr) => unapply(expr)
+ case _ => None
}
}