score:1
Accepted answer
your output expression is keeping a reference to the old x
symbol, but instead it should be a reference to a new one. therefore, you can reset all the junk references in the tree you aim to reuse by applying resetlocalattrs
from context.
how about...?
def mimpl(c: context)(bodyblock: c.expr[unit]): c.expr[x] =
c.universe.reify {
new x(new specialfunction {
override def apply() {
c.expr[unit](c.resetlocalattrs(bodyblock.tree)).splice
}
})
}
in this question, you can read a great explanation by the scala macros guy.
Source: stackoverflow.com
Related Query
- Scala macros: constructing an anonymous class
- Scala How to use extends with an anonymous class
- Scala - how to create anonymous class and avoid hiding argument names
- Using type parameter in anonymous class in Scala
- Scala compiler says my method is recursive in case when implicits and anonymous class is used
- Scala Unit to Anonymous Class
- Problem with creating java anonymous class with generics in scala
- Scala implement abstract base and mix in traits in anonymous class
- Creating an anonymous class from an abstract class in Scala - desugaring code
- Get all fields from anonymous class in Scala
- Change fields of case class based on map entries with simple type check in scala macros
- Access companion object from case class (or vice-versa) using scala type macros
- Porting to Scala 3. Macros - could not find class in classpath
- Scala call single parameter method using space in anonymous class body
- Make Scala class extends trait/abstract class with macros
- Scala - accessing an implicit class from an anonymous sub-class without the new keyword
- best techniques to debug scala code which passes around lambda bodies, anonymous class instances and things like that?
- scala macros how to get tree of specific class
- Implement static inner interface as anonymous class in Scala
- Scala wrap generic anonymous class
- How to recognize an anonymous class in a Scala macro?
- Is it possible to print the returned value of a function of different class in case of Anonymous object of scala
- Can Scala macros be defined inside a class (as methods of that class)?
- Spring + Scala + anonymous block or class
- Scala anonymous class type mismatch
- Scala - Anonymous class not getting variable of caller class
- Use scala macros to copy method from class to companion object
- Obtaining the realised type for a Scala Class using macros
- Obtain Java Class from Scala TypeTag in Macros
- Difference between object and class in Scala
More Query from same tag
- Format String to Float with two decimal places
- scala play 2.1.1 json functional syntax mapping data to a different format
- Play 2 reverse routing, get route from controller method
- Change the login form in secure social
- unlist a list of scala.xml.Elem to a single scala.xml.Elem
- Using `err` in a Child Parser
- Simple composition of implicits with Monoids in Scala
- Using org.openrdf.rio.trig.TriGWriter to create a SPARQL update
- Play framework: play.api.mvc.DefaultJWTCookieDataCodec decode: could not decode JWT: null
- Matching tokens carrying values with Scala's parser combinators
- HTTP response parsing: Seq vs Set conventions
- generate a page of news with one query with Slick
- PlayFramework 2.6.x: How to get dynamically named database connection in configurations?
- Specify Oracle schema with Slick 3.2
- monitoring results in spark Pagerank execution
- How to get full info of non-owing side of relationship after ORM in views in play framework?
- How can I reusably filter based on type in Scala?
- How to package multimodule library as one jar
- java.lang.StringIndexOutOfBoundsException: String index out of range: 0
- Why simple Scala tailrec loop for fibonacci calculation is faster in 3x times than Java loop?
- Chain records in DataFrame by using a recursive function
- spark scala extraneous input '>' ParseException in transform
- How to add "provided" dependencies back to run/test tasks' classpath?
- Dependent Typing style Equality Proofs in Scala
- Best way to mask dynamic data (timestamps) using ScalaTest
- Samples of Scala and Java code where Scala code looks simpler/has fewer lines?
- Could not find implicit value for parameter write eror, yet I defined the handler using the macro
- How to run an if else statement in Scala in Databricks streaming
- How to find the max String length of a column in Spark using dataframe?
- Is it better to use import scala.reflect.io.File or java.io.File in Scala?