scala/scala — pull request #3118 by densh (2013-11-10 22:55:59+00:00)
Title: Introduce Unliftable for Quasiquotes

This pr introduces a new `Unliftable` type class used by quasiquotes to extract custom data types out of trees:

```
trait Unliftable[T] {
def unapply(tree: Tree): Option[T]
}
```

When an implicit value of Unliftable[T] is provided this means that user can extract value of T inside of the quasiquote pattern:
```
case q"${x: T}" =>
// body
```
Where this code is semantically equivalent to:
```
case q"$x0" if implicitly[Unliftable[T]].unapply(x0).nonEmpty =>
val x: T = implicitly[Unliftable[T]].unapply(x0).get
// body
```
The major use-case for introduction of `Unliftable` is vast simplification of extraction of leaf values from the trees:
```
val "${x: Int} + ${y: Int}" = q"1 + 2"
```
Previously users had to resort to nesting manual tree subpatterns to extract such values:
```
val "${Literal(Constant(x: Int))} + ${Literal(Constant(y: Int))}" = q"1 + 2"
```

review by @retronym and @xeno-by