From e72ae708ed39ad006ef7dbbb85e116a8e6704663 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 27 Jun 2013 17:10:47 +0200 Subject: SI-7617 typedAssign no longer expands lhs This makes sure that setter and updateDynamic macros work as intended rather than in some cases expanding incorrectly or prematurely. Setter invocations are desugared from assignments of values to getters. If a typecheck of an assignment's lhs yields an invocation of a getter, then the assignment is rewritten into an invocation of a setter. However if a getter is a macro, then it just expands, destroying the prerequisite for desugaring. Therefore we need to disable expansion for the typecheck of an lhs. Similar thing happens to updateDynamic that first desugars a getter invocation into q"$target.updateDynamic($fieldName)" and then expects typedAssign to rewrite the corresponding Assign node into an additional application of a partially applied updateDynamic to a rhs. Here we also need to disable the typecheck of an lhs, because macros cannot be partially applied. --- test/files/run/t7617a/Macros_1.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/files/run/t7617a/Macros_1.scala (limited to 'test/files/run/t7617a/Macros_1.scala') diff --git a/test/files/run/t7617a/Macros_1.scala b/test/files/run/t7617a/Macros_1.scala new file mode 100644 index 0000000000..f9772c83c0 --- /dev/null +++ b/test/files/run/t7617a/Macros_1.scala @@ -0,0 +1,22 @@ +import scala.reflect.macros.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] +} -- cgit v1.2.3