diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-07-15 15:03:09 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-07-15 15:03:09 +0200 |
commit | 41491b081421989e15d7bbfb7a97c0e7669ad1d9 (patch) | |
tree | b65a640bca0110cfbd5465c50dceacda7f4bfe7f /src | |
parent | 2429603c3fe9c2287907690ceda25c599270864b (diff) | |
parent | 9d527b6558f9ecf32467b6f414175267bb44c1d7 (diff) | |
download | scala-41491b081421989e15d7bbfb7a97c0e7669ad1d9.tar.gz scala-41491b081421989e15d7bbfb7a97c0e7669ad1d9.tar.bz2 scala-41491b081421989e15d7bbfb7a97c0e7669ad1d9.zip |
Merge pull request #3858 from densh/si/8703
SI-8703 add support for blocks with just a single expression to quasiquotes
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala | 13 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/TreeGen.scala | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala index b68022afd9..392b7fc881 100644 --- a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala +++ b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala @@ -69,9 +69,16 @@ trait Parsers { self: Quasiquotes => override def makeTupleType(trees: List[Tree]): Tree = TupleTypePlaceholder(trees) // q"{ $x }" - override def makeBlock(stats: List[Tree]): Tree = stats match { - case (head @ Ident(name)) :: Nil if isHole(name) => Block(Nil, head) - case _ => super.makeBlock(stats) + override def makeBlock(stats: List[Tree]): Tree = method match { + case nme.apply => + stats match { + // we don't want to eagerly flatten trees with placeholders as they + // might have to be wrapped into a block depending on their value + case (head @ Ident(name)) :: Nil if isHole(name) => Block(Nil, head) + case _ => gen.mkBlock(stats, doFlatten = true) + } + case nme.unapply => gen.mkBlock(stats, doFlatten = false) + case other => global.abort("unreachable") } // tq"$a => $b" diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index 9066c73393..6e8e992d16 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -451,10 +451,10 @@ abstract class TreeGen { def mkSyntheticUnit() = Literal(Constant(())).updateAttachment(SyntheticUnitAttachment) /** Create block of statements `stats` */ - def mkBlock(stats: List[Tree]): Tree = + def mkBlock(stats: List[Tree], doFlatten: Boolean = true): Tree = if (stats.isEmpty) mkSyntheticUnit() else if (!stats.last.isTerm) Block(stats, mkSyntheticUnit()) - else if (stats.length == 1) stats.head + else if (stats.length == 1 && doFlatten) stats.head else Block(stats.init, stats.last) /** Create a block that wraps multiple statements but don't |