summaryrefslogblamecommitdiff
path: root/test/files/run/macro-subpatterns/Macro_1.scala
blob: 994421aa327e30d9649849968126bad30a04d2c6 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                            



                                              
                                            


                                                                                                                        


                           
                              
                                  

                   

   
import scala.reflect.macros.whitebox.Context
import language.experimental.macros

object Extractor {
  def unapply(x: Any): Any = macro unapplyImpl
  def unapplyImpl(c: Context)(x: c.Tree) = {
    import c.universe._
    import internal._
    val subpatterns = attachments(x).get[scala.reflect.internal.SymbolTable#SubpatternsAttachment].get.patterns.toString
    q"""
      new {
        def isEmpty = false
        def get = $subpatterns
        def unapply(x: Any) = this
      }.unapply($x)
    """
  }
}