diff options
author | Martin Odersky <odersky@gmail.com> | 2017-02-14 14:52:51 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-02-14 14:53:05 +0100 |
commit | 6e23a94e4732ce1ab72c4af00f209a63a04b3813 (patch) | |
tree | 9d4cc03f3d4ff74166c79fabe9663ebcf8edbec5 | |
parent | 47901c09885f8931d82a3bbc469985a50f790091 (diff) | |
download | dotty-6e23a94e4732ce1ab72c4af00f209a63a04b3813.tar.gz dotty-6e23a94e4732ce1ab72c4af00f209a63a04b3813.tar.bz2 dotty-6e23a94e4732ce1ab72c4af00f209a63a04b3813.zip |
Fix #1975: Align valdefs and for expressions for patterns
val definitions and for expressions both distinguish whether
something is a pattern or a variable binding. They no do it
the same way: `ident` or an `ident: type` is a variable binding,
everything else is a pattern. Previously, capitalized idents
were considered as bindings in valdefs but as pattern in fors.
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/Desugar.scala | 12 | ||||
-rw-r--r-- | tests/pos/i1975.scala | 5 |
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index e3102fda2..deb239143 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -559,7 +559,7 @@ object desugar { * ValDef or DefDef. */ def makePatDef(original: Tree, mods: Modifiers, pat: Tree, rhs: Tree)(implicit ctx: Context): Tree = pat match { - case VarPattern(named, tpt) => + case IdPattern(named, tpt) => derivedValDef(original, named, tpt, rhs, mods) case _ => val rhsUnchecked = makeAnnotated("scala.unchecked", rhs) @@ -816,7 +816,7 @@ object desugar { * Otherwise this gives { case pat => body } */ def makeLambda(pat: Tree, body: Tree): Tree = pat match { - case VarPattern(named, tpt) => + case IdPattern(named, tpt) => Function(derivedValDef(pat, named, tpt, EmptyTree, Modifiers(Param)) :: Nil, body) case _ => makeCaseLambda(CaseDef(pat, EmptyTree, body) :: Nil, unchecked = false) @@ -898,7 +898,9 @@ object desugar { } def isIrrefutableGenFrom(gen: GenFrom): Boolean = - gen.isInstanceOf[IrrefutableGenFrom] || isIrrefutable(gen.pat, gen.expr) + gen.isInstanceOf[IrrefutableGenFrom] || + IdPattern.unapply(gen.pat).isDefined || + isIrrefutable(gen.pat, gen.expr) /** rhs.name with a pattern filter on rhs unless `pat` is irrefutable when * matched against `rhs`. @@ -1062,9 +1064,9 @@ object desugar { TypeDef(tpnme.REFINE_CLASS, impl).withFlags(Trait) } - /** If tree is a variable pattern, return its name and type, otherwise return None. + /** If tree is of the form `id` or `id: T`, return its name and type, otherwise return None. */ - private object VarPattern { + private object IdPattern { def unapply(tree: Tree)(implicit ctx: Context): Option[VarInfo] = tree match { case id: Ident => Some(id, TypeTree()) case Typed(id: Ident, tpt) => Some((id, tpt)) diff --git a/tests/pos/i1975.scala b/tests/pos/i1975.scala new file mode 100644 index 000000000..4657a6735 --- /dev/null +++ b/tests/pos/i1975.scala @@ -0,0 +1,5 @@ +object Test { + val X = Seq(1, 2) + + for (X <- Seq(3, 4)) yield println(X) +} |