aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-03-06 19:14:11 +0100
committerMartin Odersky <odersky@gmail.com>2016-03-12 16:08:37 +0100
commit54f6399b6625cb8f841c1e5965841d46a3e9230c (patch)
tree5b3dccf116585eb09174627cb3455712af49730d
parentec90a19852dbeeaaa10c5e95c3f97d605386e1ca (diff)
downloaddotty-54f6399b6625cb8f841c1e5965841d46a3e9230c.tar.gz
dotty-54f6399b6625cb8f841c1e5965841d46a3e9230c.tar.bz2
dotty-54f6399b6625cb8f841c1e5965841d46a3e9230c.zip
Fix desugaring of lazy patterns.
Selectors should be defs, not lazy vals.
-rw-r--r--src/dotty/tools/dotc/ast/Desugar.scala23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala
index 8ba155097..d3dc88b84 100644
--- a/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/src/dotty/tools/dotc/ast/Desugar.scala
@@ -498,16 +498,16 @@ object desugar {
/** If `pat` is a variable pattern,
*
- * val/var p = e
+ * val/var/lazy val p = e
*
* Otherwise, in case there is exactly one variable x_1 in pattern
- * val/var p = e ==> val/var x_1 = (e: @unchecked) match (case p => (x_1))
+ * val/var/lazy val p = e ==> val/var x_1 = (e: @unchecked) match (case p => (x_1))
*
* in case there are zero or more than one variables in pattern
- * val/var p = e ==> private synthetic val t$ = (e: @unchecked) match (case p => (x_1, ..., x_N))
- * val/var x_1 = t$._1
+ * val/var/lazy p = e ==> private synthetic [lazy] val t$ = (e: @unchecked) match (case p => (x_1, ..., x_N))
+ * val/var/def x_1 = t$._1
* ...
- * val/var x_N = t$._N
+ * val/var/def x_N = t$._N
* If the original pattern variable carries a type annotation, so does the corresponding
* ValDef.
*/
@@ -533,12 +533,16 @@ object desugar {
derivedValDef(named, tpt, matchExpr, mods)
case _ =>
val tmpName = ctx.freshName().toTermName
- val patFlags = mods.flags & AccessFlags | Synthetic | (mods.flags & Lazy)
- val firstDef = ValDef(tmpName, TypeTree(), matchExpr).withFlags(patFlags)
+ val patMods = mods & (AccessFlags | Lazy) | Synthetic
+ val firstDef =
+ ValDef(tmpName, TypeTree(), matchExpr)
+ .withPos(pat.pos.union(rhs.pos)).withMods(patMods)
def selector(n: Int) = Select(Ident(tmpName), nme.selectorName(n))
val restDefs =
for (((named, tpt), n) <- vars.zipWithIndex)
- yield derivedValDef(named, tpt, selector(n), mods)
+ yield
+ if (mods is Lazy) derivedDefDef(named, tpt, selector(n), mods &~ Lazy)
+ else derivedValDef(named, tpt, selector(n), mods)
flatTree(firstDef :: restDefs)
}
}
@@ -635,6 +639,9 @@ object desugar {
private def derivedValDef(named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers) =
ValDef(named.name.asTermName, tpt, rhs).withMods(mods).withPos(named.pos)
+ private def derivedDefDef(named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers) =
+ DefDef(named.name.asTermName, Nil, Nil, tpt, rhs).withMods(mods).withPos(named.pos)
+
/** Main desugaring method */
def apply(tree: Tree)(implicit ctx: Context): Tree = {