Designed to reliably work with production releases of the Scala Compiler, the Macro Paradise plugin makes the latest macro developments available long before they end up in future shipping releases of Scala.
Questions tagged [scala-macro-paradise]
77 questions
4
votes
1 answer
Accessing class definition by name from scala macro
I'm trying to create a Scala macro which defines a single a Class argument, and which modifies the class to which it is attached based on the implementation of the Class which is provided as an argument.
//Simple class with a few arguments
class…

hmoens
- 83
- 6
4
votes
1 answer
What does it mean when macro annotation cannot be used in the same compilation that defines it?
I am curious about this statement:
Error:(3, 18) ...another possibility is that you try to use macro
annotation in the same compilation run that defines it)
I tried googling and found this:
Finally, remember that using macros requires…
user1187135
4
votes
1 answer
How to Typecheck a DefDef
Within an annotation Macro, I'm enumerating members of a class and want the types of the methods that I find.
So I happily iterate over the body of the class, and collect all the DefDef members.
... which I can't typecheck.
For each DefDef I've…

Kevin Wright
- 49,540
- 9
- 105
- 155
3
votes
1 answer
When are Scala macro annotations executed? (macro paradise)
I tried to implement the Scala macro annotations example as described in the documentation. I managed to compile the macro annotations before the actual project which uses them, i.e., the @compileTimeOnly("enable macro paradise to expand macro…

Maarten
- 207
- 2
- 13
3
votes
1 answer
Scalameta: Identify particular annotations
I want to auto-generate REST API models in Scala using scalameta annotation macros. Specifically, given:
@Resource case class User(
@get id : Int,
@get @post @patch name : String,
@get @post email :…

pathikrit
- 32,469
- 37
- 142
- 221
3
votes
1 answer
Why does this public field have a PRIVATE flag?
I'm writing a Scala macro and am traversing the tree to find non-private fields in classes.
Consider this code that the macro looks at:
class Foo {
val bar: String = "test"
}
I'm traversing this code and getting to bar's ValDef. It has only two…

Omer van Kloeten
- 11,800
- 9
- 42
- 53
3
votes
1 answer
easiest way for users to include scalamacros paradise
I have just added some macro annotations to my library. In my library build, I include
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
to enable macro paradise.
In my users' projects that consume the macros, I…

john sullivan
- 1,898
- 2
- 13
- 21
3
votes
1 answer
Macro annotation with default arguments
Getting Parameters from Scala Macro Annotation explains how to get parameters from a macro annotation. However, if I have several parameters with default values:
class Foo(b: Boolean = false, i: Int = 0) extends StaticAnnotation { ... }
I need to…

Alexey Romanov
- 167,066
- 35
- 309
- 487
3
votes
1 answer
scala macro with a import statement not working
I am annotating a trait such as:
@ScreenModel
trait TestTrait {
.......
}
And then I have got the implementation of @ScreenModel with something like:
def impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
val…

lqbweb
- 1,684
- 3
- 19
- 33
3
votes
2 answers
How to evaluate an expression inside a Scala macro?
I'm trying to evaluate an Expr inside a macro using the Context#eval method:
//Dummy implementation
def evalArrayTree(c: Context)(a: c.Expr[ArrayTree]): c.Expr[Array[Double]] = {
import c.universe._
println( c.eval(a) )
val tree = reify(…

paradigmatic
- 40,153
- 18
- 88
- 147
2
votes
0 answers
Scala: How to access associated parameter values of a macro annotation in the macro implementation?
I am working with macro annotations (link) that are part of the macro paradise of Scala.
In their example they use a macro annotation called identity which takes no parameters. However, the macro annotation I am trying to implement does require an…

Maarten
- 207
- 2
- 13
2
votes
0 answers
Vampiric methods, type provider macros and missing runtime.VolatileObjectRef
I am trying to write a type provider macro that uses the vampiric methods trick described in this gist; this is a minimal model of my implementation:
object DeriveFamily {
def minimal: Any = macro DeriveFamilyMacros.minimal
}
object…

Aldo Stracquadanio
- 6,167
- 1
- 23
- 34
2
votes
1 answer
Scala Macros: Generated class fails to compile with unimplemented members
My problem is that my generated class' members are not getting recognised as implemented. This is being built for Scala 2.10/2.11/2.12 with 2.11 being the default. Using macroparadise 2.10.
Goal of this was to mark the some traits as freezable and…

Senkwich
- 1,022
- 1
- 9
- 17
2
votes
1 answer
Scala macro annotation - case class with type parameters
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…

dbaumann
- 190
- 9
2
votes
0 answers
Scala macro paradise using jar instead multiproject build in play framework
I have got following question:
I have my play application lets call it PlayApp. Inside this Play application I've created subproject (in dir /MyLib inside playApp)let's call it MyLib. This MyLib project have some macro with class annotations. I want…

Bartosz Bąbol
- 81
- 5