Skip to content

Commit

Permalink
SI-8275 allow to directly extract block contents of the case def
Browse files Browse the repository at this point in the history
Due to the fact that blocks in cases are implicit one might expect to be
able to extract its contents with `..$`.
  • Loading branch information
densh committed Feb 28, 2014
1 parent 13e7b81 commit e17c055
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/StdNames.scala
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
Expand Up @@ -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")
}
}

0 comments on commit e17c055

Please sign in to comment.