I just started studying scala compile-time reflection, and I got introduced to quasiquotes by the Scala official guides.
One concept I'm still struggling with is how am I supposed to work with quasiquotes (or reify, for that matter) if I want to…
I need to compile function and then evaluate it with different parameters of type List[Map[String, AnyRef]].
I have the following code that does not compile with such the type but compiles with simple type like List[Int].
I found that there are…
I'm trying to write a simple macro annotation for case classes which adds a method to the companion object. The catch is that the new method must account for type parameters on the annotated case class.
Here's the test that I need to pass
package…
This is easier to explain in code. I want to do something like:
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
val toolbox = currentMirror.mkToolBox()
val universe: scala.reflect.runtime.universe.type =…
I'm currently using:
annottees map (_.tree) match {
case (classDef @ q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }")
:: Nil =>
to extract both the classDef and the…
In the scala console I can do the following without a problem :
scala> val tree = q"def f():MySuperType[(Char,Char)]"
tree: universe.DefDef = def f(): MySuperType[scala.Tuple2[Char, Char]]
scala> val q"def $f():$d" = tree
f: universe.TermName =…
I'm trying to make a type-provider that gives updated case classes.
How might I splice in a type and a default value (or omit the default value)?
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
import…
I am developing a macro and in its implementation I get the weakTypeOf T where T is a type parameter of the macro function. I want to splice info, from the method definitions of this concrete type to a new class declaration tree. I cannot get the…
I'm trying to create a match statement using macros, that matches all subclasses of a given type.
But I have trouble with extracting the field values of the case classes.
For example:
sealed abstract class Foobar
case class Foo(x:Int,f:Foobar)…
With Scala2 I could implement a macro and generate types using tq quasiquote syntax, for eg:
q"""
new Foo {
type Bar = ${tq"(..$params)"}
}
"""
I am able to do two things with this syntax -
Able to define a type Bar based on the…
I cannot manage to get the companion object / singleton from a class type in Scala macro / quasiquotes. Tried to follow https://docs.scala-lang.org/overviews/quasiquotes/type-details.html#singleton-type, the given example works but it is based on a…
Suppose i have some class with some methods
class Clz ... {
def someMethod: Map[String, Long] = ...
def id: Long = 0L
}
i'm need to reuse someMethod and overwrite id
i don't know why but it's throw Stackoverflow and also i'm need to do…
I have scala macro that creates the constructor for a class on the fly.
So for example if we have a class case class PersonConfig(name: String, age: Int, isFemale: Boolean). I have the Tree structure for the classname and the arguments passed to the…