summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/reflect
diff options
context:
space:
mode:
authorDenys Shabalin <denys.shabalin@typesafe.com>2014-07-02 14:10:42 +0200
committerDenys Shabalin <denys.shabalin@typesafe.com>2014-07-02 14:10:42 +0200
commit14d1fe0c35f4ab07a0535adbdf8acbcbd1208363 (patch)
treecdf75636f4f558b94159bd4f25083d8527aa71cd /src/compiler/scala/tools/reflect
parente67146c6e8758b070f6ce4eeb43d289980bfe51a (diff)
downloadscala-14d1fe0c35f4ab07a0535adbdf8acbcbd1208363.tar.gz
scala-14d1fe0c35f4ab07a0535adbdf8acbcbd1208363.tar.bz2
scala-14d1fe0c35f4ab07a0535adbdf8acbcbd1208363.zip
SI-8703 add support for blocks with just a single expression to quasiquotes
Previously it was impossible to match a block that was constructed as Block(Nil, term) Due to the fact that quasiquotes always flatten those into just term. This is a correct behaviour for construction (for sake of consistency with parser) but doing it in deconstruction mode make it impossible to match such blocks which could have been constructed manually somewhere. To fix this we just disable block flattening in deconstruction mode. Interestingly enough this doesn't break existing code due to the fact that quasiquote's block matcher also matches expressions as single-element blocks. This allows to match single-element blocks with patterns like q"{ $foo }".
Diffstat (limited to 'src/compiler/scala/tools/reflect')
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala
index b68022afd9..460d02c218 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala
@@ -69,9 +69,14 @@ 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 {
+ case (head @ Ident(name)) :: Nil if isHole(name) => Block(Nil, head)
+ case _ => super.makeBlock(stats)
+ }
+ case nme.unapply => gen.mkBlock(stats, doFlatten = false)
+ case other => global.abort("unreachable")
}
// tq"$a => $b"