Scala macros is a facility for Scala—a general-purpose programming language—that permits compile-time metaprogramming against Scala syntax trees, from within the Scala language.
Questions tagged [scala-macros]
774 questions
0
votes
1 answer
Expand scala splat at compile time using macros and eval
I have a sequence, val xs: Seq[T], and a function f(xs: T*).
I'd like to write a macro that expands f(xs: _*) to f(x1, x2, ... xn) at compile time, but I'm having a lot of trouble successfully evaling the Expr in the macro. I've tried a few…

Leo
- 3,036
- 3
- 13
- 12
0
votes
0 answers
How to get a raw sequence of reified values in scala macro
I have a c.Expr[Seq[T]] and I want to get a Seq[c.Expr[T]] so I can pass it to a library function that processes it and produces a different final result Expr.
I found this answer explaining how to go in the opposite direction but I can't quite…

Leo
- 3,036
- 3
- 13
- 12
0
votes
1 answer
Scala annotation macro only works with pre-defined classes
Note: There's an EDIT below!
Note: There's another EDIT below!
I have written a Scala annotation macro that is being passed a class and creates (or rather populates) a case object. The name of the case object is the same as the name of the passed…

typeduke
- 6,494
- 6
- 25
- 34
0
votes
1 answer
Using Scala macros, can i make implementer of method call super?
Can Scala macros be used to make implementers of a method in a trait invoke the super method. For instance like this:
trait Super {
//some macro magic here: list = super.list ++ child.list
def list: List[String] = List("ein", "zwei",…

eirirlar
- 814
- 6
- 24
0
votes
1 answer
Scala map collection case-class to Map()
I have 2 case-classes:
case class OutlierPortal(portal: String, timeData: Seq[OutlierPortalTimeSeriesData])
and
case class OutlierPortalTimeSeriesData(period: Timestamp, totalAmount: Double, isOutlier: Int)
or respectively a…

Georg Heiler
- 16,916
- 36
- 162
- 292
0
votes
2 answers
Obtain Java Class from Scala TypeTag in Macros
According to this question/answer Any way to obtain a Java class from a Scala (2.10) type tag or symbol?
I should use runtimeClass to obtain the Class from a type.
But if I do reflection in Macros I don't have access to runtimeClass.
How can I do?

Joan
- 4,079
- 2
- 28
- 37
0
votes
2 answers
Can Scala macros be defined inside a class (as methods of that class)?
I need Scala macros (reify, quasiquote, macro impl) for my Scala assertions library.
I want to be able to do this:
object1.assertEquals(object2) // success: object1 = object2
Or like this:
3.assertEquals(1 + 1) // failure: 1 + 1 /= 3
Can Scala…

Michael Lafayette
- 2,972
- 3
- 20
- 54
0
votes
2 answers
Scala quasiquote macro example broken - type signatures off
I took this Scala quasiquote example from the book "Programming Scala" (2nd Edition)
I am getting this error: https://issues.scala-lang.org/browse/SI-9711
The type inference says "Trees#Tree", but the type inference is off.
import…

Michael Lafayette
- 2,972
- 3
- 20
- 54
0
votes
1 answer
How to tell an object is companion object of a Traversable(List, Seq..) in macro
case q"$pack.$coll.apply[..$t](..$v)" if isTraverable(coll) => xxx
I am trying to match Array.apply, List.apply, Seq.apply, Set.apply and other Traverable apply method.
How should I implement isTraverable(coll)

jilen
- 5,633
- 3
- 35
- 84
0
votes
2 answers
Macro annotation to override toString of Scala function
How to write macro annotation which looks in usage like @named("+2") _ + 2 and produces:
new (Int => Int) {
override def toString(): String = "+2"
def apply(x: Int): Int = x + 2
}

Andriy Plokhotnyuk
- 7,883
- 2
- 44
- 68
0
votes
1 answer
scala quasiquotes: comparing types
As an overview, I am trying to dynamically create a constructor for a case class from a Cassandra Java Row using reflection to find the primary constructor for the case class, and then trying to extract the values from the Cassandra Row.…

thurston sandberg
- 33
- 6
0
votes
1 answer
Use a static Java declaration in macro implementation
I am trying to use a static method on a Java class, T, in a macro implementation:
def macroImpl[T : c.WeakTypeTag](c: Context): c.Expr[ResultType] = {
import c.universe._
val tpe = weakTypeOf[T]
val someStaticMethod =…

mushroom
- 6,201
- 5
- 36
- 63
0
votes
2 answers
Matching two types to determine type parameters
I'm writing some macros in Scala.
Let's assume I have some Type, e.g. typeOf[Map[String,Set[Int]]] and a similar type where some of its parts have been replaced with undetermined type parameters, e.g. typeOf[Map[String,Set[T]]] where T is…

ghik
- 10,706
- 1
- 37
- 50
0
votes
1 answer
annotation macro that rewrites and impls a trait, generics not processed correctly
I am writing a macro that needs to create a class that rewrites a trait, having the same methods/args of the trait but different return type.
So say we got:
trait MyTrait[T]
{
def x(t1: T)(t2: T): T
}
@AnnProxy
class MyClass[T] extends…

kostas.kougios
- 945
- 10
- 21
0
votes
1 answer
get the Type of a tparam of a Macro Annotation
Say I have a macro annotation AnnProxy and the following code:
trait MyTrait
{
def x: Int
}
@AnnProxy
class MyClass extends MyTrait
I now need to get the Type of MyTrait so that I can proxy it's methods. So far my code looks…

kostas.kougios
- 945
- 10
- 21