summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala84
-rw-r--r--test/files/run/t6646.check2
-rw-r--r--test/files/run/t6646.scala6
3 files changed, 67 insertions, 25 deletions
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 56a0bac72b..90f4f6fc8f 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -245,31 +245,65 @@ abstract class TreeInfo {
isSelfConstrCall(tree1) || isSuperConstrCall(tree1)
}
- /** Is this tree comprised of nothing but identifiers,
- * but possibly in bindings or tuples? For instance:
- *
- * {{{
- * foo @ (bar, (baz, quux))
- * }}}
- *
- * is a variable pattern; if the structure matches,
- * then the remainder is inevitable.
- *
- * The following are not variable patterns.
- *
- * {{{
- * foo @ (bar, (`baz`, Quux))
- * foo @ (bar, Quux)
- * }}}
- */
- def isVarPatternDeep(tree: Tree): Boolean = tree match {
- case Bind(name, pat) => isVarPatternDeep(pat)
- case Ident(name) => isVarPattern(tree)
- case Apply(sel, args) =>
- ( isReferenceToScalaMember(sel, TupleClass(args.size).name.toTermName)
- && (args forall isVarPatternDeep)
- )
- case _ => false
+ /**
+ * Does this tree represent an irrefutable pattern match
+ * in the position `for { <tree> <- expr }` based only
+ * on information at the `parser` phase? To qualify, there
+ * may be no Stable Identifier Patterns.
+ *
+ * For instance:
+ *
+ * {{{
+ * foo @ (bar, (baz, quux))
+ * }}}
+ *
+ * is a variable pattern; if the structure matches,
+ * then the remainder is inevitable.
+ *
+ * The following are not variable patterns.
+ *
+ * {{{
+ * foo @ (bar, (`baz`, quux)) // back quoted ident, not at top level
+ * foo @ (bar, Quux) // UpperCase ident, not at top level
+ * }}}
+ *
+ * If the pattern is a simple identifier, it is always
+ * a variable pattern. For example, the following
+ * introduce new bindings:
+ *
+ * {{{
+ * for { X <- xs } yield X
+ * for { `backquoted` <- xs } yield `backquoted`
+ * }}}
+ *
+ * Note that this differs from a case clause:
+ *
+ * {{{
+ * object X
+ * scrut match {
+ * case X => // case _ if scrut == X
+ * }
+ * }}}
+ *
+ * Background: [[https://groups.google.com/d/msg/scala-internals/qwa_XOw_7Ks/IktkeTBYqg0J]]
+ *
+ */
+ def isVarPatternDeep(tree: Tree): Boolean = {
+ def isVarPatternDeep0(tree: Tree): Boolean = {
+ tree match {
+ case Bind(name, pat) => isVarPatternDeep0(pat)
+ case Ident(name) => isVarPattern(tree)
+ case Apply(sel, args) =>
+ ( isReferenceToScalaMember(sel, TupleClass(args.size).name.toTermName)
+ && (args forall isVarPatternDeep0)
+ )
+ case _ => false
+ }
+ }
+ tree match {
+ case Ident(name) => true
+ case _ => isVarPatternDeep0(tree)
+ }
}
/** Is tree a variable pattern? */
diff --git a/test/files/run/t6646.check b/test/files/run/t6646.check
index e27b5b9efb..b0b7ad32f3 100644
--- a/test/files/run/t6646.check
+++ b/test/files/run/t6646.check
@@ -1,3 +1,5 @@
Found NotNull
Found lower
Found 2
+A single ident is always a pattern
+A single ident is always a pattern
diff --git a/test/files/run/t6646.scala b/test/files/run/t6646.scala
index 9418bfafb1..150b0df11e 100644
--- a/test/files/run/t6646.scala
+++ b/test/files/run/t6646.scala
@@ -6,8 +6,14 @@ case object lower extends ColumnOption
object Test {
def main(args: Array[String]) {
val l = List(PrimaryKey, NotNull, lower)
+
+ // withFilter must be generated in these
for (option @ NotNull <- l) println("Found " + option)
for (option @ `lower` <- l) println("Found " + option)
for ((`lower`, i) <- l.zipWithIndex) println("Found " + i)
+
+ // no withFilter
+ for (X <- List("A single ident is always a pattern")) println(X)
+ for (`x` <- List("A single ident is always a pattern")) println(`x`)
}
}