From 14d1fe0c35f4ab07a0535adbdf8acbcbd1208363 Mon Sep 17 00:00:00 2001 From: Denys Shabalin Date: Wed, 2 Jul 2014 14:10:42 +0200 Subject: 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 }". --- test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/files/scalacheck') diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala index 49ffaff630..07e8f3faac 100644 --- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala @@ -246,4 +246,11 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction assert(f ≈ `new`) assert(argss.isEmpty) } + + property("SI-8703 extract block with single expression") = test { + val q"{ $a }" = Block(Nil, q"1") + val Literal(Constant(1)) = a + val q"{ $b }" = q"2" + val Literal(Constant(2)) = b + } } -- cgit v1.2.3