Skip to content
Browse files

SI-6646 Fix regression in for desugaring.

The early check in the parser of pattern irrefutability,
added in c82ecab, failed to consider InitCaps and
`backquoted` identifiers.
  • Loading branch information...
1 parent 8b59843 commit 8b2caf0746fd4405f2d47b54d17d484e6603c89d @retronym retronym committed
View
2 src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -285,7 +285,7 @@ abstract class TreeBuilder {
def makeGenerator(pos: Position, pat: Tree, valeq: Boolean, rhs: Tree): Enumerator = {
val pat1 = patvarTransformer.transform(pat)
val rhs1 =
- if (valeq || treeInfo.isVariablePattern(pat)) rhs
+ if (valeq || treeInfo.isVarPatternDeep(pat)) rhs
else makeFilter(rhs, pat1.duplicate, nme.CHECK_IF_REFUTABLE_STRING)
if (valeq) ValEq(pos, pat1, rhs1)
View
45 src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -245,6 +245,33 @@ 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
+ }
+
/** Is tree a variable pattern? */
def isVarPattern(pat: Tree): Boolean = pat match {
case x: Ident => !x.isBackquoted && nme.isVariableName(x.name)
@@ -330,24 +357,6 @@ abstract class TreeInfo {
case _ => false
}
- /** 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.
- */
- def isVariablePattern(tree: Tree): Boolean = tree match {
- case Bind(name, pat) => isVariablePattern(pat)
- case Ident(name) => true
- case Apply(sel, args) =>
- ( isReferenceToScalaMember(sel, TupleClass(args.size).name.toTermName)
- && (args forall isVariablePattern)
- )
- case _ => false
- }
-
/** Is this argument node of the form <expr> : _* ?
*/
def isWildcardStarArg(tree: Tree): Boolean = tree match {
View
3 test/files/run/t6646.check
@@ -0,0 +1,3 @@
+Found NotNull
+Found lower
+Found 2
View
13 test/files/run/t6646.scala
@@ -0,0 +1,13 @@
+sealed trait ColumnOption
+case object NotNull extends ColumnOption
+case object PrimaryKey extends ColumnOption
+case object lower extends ColumnOption
+
+object Test {
+ def main(args: Array[String]) {
+ val l = List(PrimaryKey, NotNull, lower)
+ for (option @ NotNull <- l) println("Found " + option)
+ for (option @ `lower` <- l) println("Found " + option)
+ for ((`lower`, i) <- l.zipWithIndex) println("Found " + i)
+ }
+}

0 comments on commit 8b2caf0

Please sign in to comment.
Something went wrong with that request. Please try again.