From e17c055df049c6f8b42d31629e70df5bb44e2bfb Mon Sep 17 00:00:00 2001 From: Denys Shabalin Date: Mon, 24 Feb 2014 15:10:39 +0100 Subject: [PATCH] SI-8275 allow to directly extract block contents of the case def Due to the fact that blocks in cases are implicit one might expect to be able to extract its contents with `..$`. --- .../scala/tools/reflect/quasiquotes/Reifiers.scala | 2 ++ src/reflect/scala/reflect/internal/StdNames.scala | 1 + .../quasiquotes/TermDeconstructionProps.scala | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala index 61fb22bc7356..4937bfc35dc3 100644 --- a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala +++ b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala @@ -206,6 +206,8 @@ trait Reifiers { self: Quasiquotes => reifyBuildCall(nme.SyntacticTry, block, catches, finalizer) case Match(selector, cases) => reifyBuildCall(nme.SyntacticMatch, selector, cases) + case CaseDef(pat, guard, body) if fillListHole.isDefinedAt(body) => + mirrorCall(nme.CaseDef, reify(pat), reify(guard), mirrorBuildCall(nme.SyntacticBlock, fillListHole(body))) // parser emits trees with scala package symbol to ensure // that some names hygienically point to various scala package // members; we need to preserve this symbol to preserve diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index f3467ff9f449..339923a061d1 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -580,6 +580,7 @@ trait StdNames { val AnyVal: NameType = "AnyVal" val Apply: NameType = "Apply" val ArrayAnnotArg: NameType = "ArrayAnnotArg" + val CaseDef: NameType = "CaseDef" val ClassInfoType: NameType = "ClassInfoType" val ConstantType: NameType = "ConstantType" val EmptyPackage: NameType = "EmptyPackage" diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala index 7c9b5ead20ac..c77946c2919e 100644 --- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala @@ -175,4 +175,15 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction assert(x ≈ q"x") val q"{ _ * _ }" = q"{ _ * _ }" } + + property("si-8275 a") = test { + val cq"_ => ..$stats" = cq"_ => foo; bar" + assert(stats ≈ List(q"foo", q"bar")) + } + + property("si-8275 b") = test { + val cq"_ => ..$init; $last" = cq"_ => a; b; c" + assert(init ≈ List(q"a", q"b")) + assert(last ≈ q"c") + } }