summaryrefslogtreecommitdiff
path: root/test/files/run/macro-whitebox-extractor/Macros_1.scala
blob: 64053b8a24e096e706dcbb08f4ad5408b378063c (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.WhiteboxContext
import language.experimental.macros

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

object Macros {
  def unapplyImpl(c: WhiteboxContext)(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)
    """
  }
}