Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defining a setter as a macro won't work #7617

Closed
scabug opened this issue Jun 27, 2013 · 3 comments
Closed

defining a setter as a macro won't work #7617

scabug opened this issue Jun 27, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jun 27, 2013

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 Test extends App {
  object Module {
    def setVal(value: String): Unit = ???
    def getVal(): String = ???

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

  Module.value = ""
}
@scabug
Copy link
Author

@scabug scabug commented Jun 27, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7617?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.2, 2.11.0-M3

@scabug
Copy link
Author

@scabug scabug commented Jun 27, 2013

@xeno-by said:
Along the same lines:

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

object Macros {
  def impl(c: Context)(name: c.Expr[String])(value: c.Expr[Any]) = {
    import c.universe._
    reify(println(s"${name.splice} = ${value.splice}"))
  }
}
import scala.language.dynamics

class C extends Dynamic {
  def updateDynamic(name: String)(value: Any) = macro Macros.impl
}

object Test extends App {
  val c = new C
  c.foo = 2
}
16:54 ~/Projects/Kepler_7617/sandbox (ticket/7617)$ ss
Test.scala:9: error: macros cannot be partially applied
  c.foo = 2
  ^
one error found

@scabug
Copy link
Author

@scabug scabug commented Jun 27, 2013

@scabug scabug closed this Jul 12, 2013
@scabug scabug added this to the 2.10.3-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants