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
25
votes
3 answers
Extracting the complete call graph of a scala project (tough one)
I would like to extract from a given Scala project, the call graph of all methods which are part of the project's own source.
As I understand, the presentation compiler doesn't enable that, and it requires going down all the way down to the actual…

matanster
- 15,072
- 19
- 88
- 167
10
votes
1 answer
Use Scala macros to generate methods
I want to generate aliases of methods using annotation macros in Scala 2.11+. I am not even sure that is even possible. If yes, how?
Example - Given this below, I want the annotation macros to expand into
class Socket {
@alias(aliases = Seq("!",…

pathikrit
- 32,469
- 37
- 142
- 221
7
votes
2 answers
Macro Annotations in Scala 3
The following is a quote from Macros: the Plan for Scala 3 from more than 3 years ago:
For instance, one will be able to define a macro annotation @json that adds a JSON serializer to a type.
Any idea how/if this is actually possible in Scala…

Koosha
- 1,492
- 7
- 19
6
votes
1 answer
new-style ("inline") macros require scala.meta
I just updated to scala meta 2.0.0-M1 and with the latest scala 2.12.3 and now macros no longer compile. The only change i made was to change the meta version from 1.8.0 to 2.0.0-M1.
ERROR: new-style ("inline") macros require scala.meta
Does anybody…

Will
- 151
- 4
6
votes
0 answers
Accessing class tree from its field's tree
I'd like to write a macro which enriches case classes. When I declare my case class like this:
case class User(int id, @tagged name)
I want to be able to inject some stuff into the Tree of this class having only annottees. So far I was only able…

kciesielski
- 1,178
- 9
- 18
6
votes
1 answer
Scala recursive macro?
I was wondering whether Scala supports recursive macro expansion e.g. I am trying to write a lens library with a lensing macro that does this:
case class C(d: Int)
case class B(c: C)
case class A(b: B)
val a = A(B(C(10))
val aa = lens(a)(_.b.c.d)(_…

pathikrit
- 32,469
- 37
- 142
- 221
6
votes
3 answers
Scala macro to print code?
I want to do something like this:
def assuming[A](condition: => Boolean)(f: => A): A = {
require(condition, /* print source-code of condition */)
f
}
Sample usage:
def fib(n: Int) = n match { // yes, yes, I know this is not efficient
case 0…

pathikrit
- 32,469
- 37
- 142
- 221
5
votes
1 answer
SBT Plugin: How to add compiler plugin as a dependency that is not propagated downstream?
I'm writing a SBT plugin. I would like to use Circe JSON library, but it requires the Macro Paradise compiler plugin on Scala 2.10.
Normally you add compiler plugins to build.sbt and SBT plugins to project/plugins.sbt.
Now when you're building a SBT…

mirosval
- 6,671
- 3
- 32
- 46
5
votes
1 answer
Scaladoc generation fails when referencing methods generated by annotation macros
I have two classes, call them Foo and Fizz. Foo uses an annotation macro called expand to make aliases of some of its methods (the actual implementation does a little more than creating aliases, but the simple version still exhibits the problem that…

Michael Zajac
- 55,144
- 7
- 113
- 138
5
votes
1 answer
Scala Macro: Create new classes with Option types
I want to write a macro given this:
@MetaRest case class User(
@get id : Int,
@get @post @patch name : String,
@get @post email : String,
registeredOn :…

pathikrit
- 32,469
- 37
- 142
- 221
4
votes
1 answer
Scala: is it possible to annotate a constructor field of a class using a macro-annotation? (macro paradise)
I am trying to annotate the constructor values of a class using macro-annotations. Assume that a macro-annotation called @identity is implemented and is used as follows in the class definition of class A:
class A(@identity val foo: String, // causes…

Maarten
- 207
- 2
- 13
4
votes
0 answers
Recursively wrapping method invocations with compiler plugins/macros
OUTLINE
I have an API that looks something like this:
package com.example
object ExternalApi {
def create[T <: SpecialElement](elem: T): TypeConstructor[T] =
TypeConstructor(elem)
def create1[T <: SpecialElement](elem: T):…

mikołak
- 9,605
- 1
- 48
- 70
4
votes
1 answer
setting correct scala version on scala ide
I'm trying to work on a project on scala IDE but I've having build problems on scala IDE.
On sbt the project builds fine. I used the eclipse sbt plugin and imported the project on scala IDE. There were build errors, which makes the ide close to…

user2759511
- 640
- 7
- 16
4
votes
1 answer
Preserve method parameter names in scala macro
I have an interface:
trait MyInterface {
def doSomething(usefulName : Int) : Unit
}
I have a macro that iterates over the methods of the interface and does stuff with the method names and parameters. I access the method names by doing something…

mushroom
- 6,201
- 5
- 36
- 63
4
votes
0 answers
Creating a Scala macro that expands into a class definition
As the title suggests, I am trying to create a Scala macro that generates a class definition. Basically I want to eventually do the following:
classify("StandardEvent", Map("name" -> String, "id" -> Int))
// should at compile-time expand to
case…

typeduke
- 6,494
- 6
- 25
- 34