summaryrefslogtreecommitdiff
path: root/test/files/run/macro-whitebox-extractor/Macros_1.scala
blob: d394c0241a005cb3d3ca030660d731329c26f41f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import scala.reflect.macros.whitebox.Context
import language.experimental.macros

object Extractor {
  def unapply(x: Int): Any = macro Macros.unapplyImpl
}

object Macros {
  def unapplyImpl(c: Context)(x: c.Tree) = {
    import c.universe._
    q"""
      new {
        class Match(x: Int) {
          def isEmpty = false
          def get = x
        }
        def unapply(x: Int) = new Match(x)
      }.unapply($x)
    """
  }
}