summaryrefslogtreecommitdiff
path: root/test/files/run/macro-declared-in-implicit-class/Impls_Macros_1.scala
blob: e5fb4bcdf3f268aeec9c8d86349bc2a151385b84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import scala.reflect.makro.{Context => Ctx}

object Impls {
  def toOptionOfInt(c: Ctx) = {
    import c.{prefix => prefix}
    import c.universe._
    val printPrefix = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("prefix = " + prefix))))
    val body = Block(printPrefix, Apply(Ident(definitions.SomeModule), List(Select(Select(prefix.tree, newTermName("x")), newTermName("toInt")))))
    c.Expr[Option[Int]](body)
  }
}

object Macros {
  implicit def foo(x: String): Foo = new Foo(x)

  class Foo(val x: String) {
    def toOptionOfInt = macro Impls.toOptionOfInt
  }
}