aboutsummaryrefslogtreecommitdiff
path: root/tests/disabled/macro/run/t7617a/Macros_1.scala
blob: 77b18c20e28256594ddef72c3114009d7de62bb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import scala.reflect.macros.blackbox.Context
import language.experimental.macros

object Macros {
  def getValueImpl[T](c: Context): c.Expr[T] = {
    import c.universe._
    c.Expr[T](Apply(Select(c.prefix.tree, newTermName("getVal")), Nil))
  }
  def setValueImpl[T](c: Context)(value: c.Expr[T]): c.Expr[Unit] = {
    import c.universe._
    c.Expr[Unit](Apply(Select(c.prefix.tree, newTermName("setVal")), List(value.tree)))
  }
}

object Module {
  private var _val: String = "hello"
  def setVal(value: String): Unit = this._val = value
  def getVal(): String = this._val

  def value: String = macro Macros.getValueImpl[String]
  def value_=(value: String): Unit = macro Macros.setValueImpl[String]
}