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
0 answers
Scala macro deprecated
I start learning this complex feature of Scala, but recently I went to Scala days and Martin Odersky mention that scala macro was an experiment and now is deprecated.
Then I had no chance to ask what similar feature we will have Instead
of macros,…

paul
- 12,873
- 23
- 91
- 153
0
votes
1 answer
Macros/Shapeless to control string value in method
I'm creating a DSL where users have a given when then, where they pass a string with the action they want.
All those actions are controlled using some regular expressions.
Now using shapeless or macros I would like to control what users compones…

paul
- 12,873
- 23
- 91
- 153
0
votes
1 answer
Partial application of Scala macros
The example illustrating the problem:
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
object Test {
def foo1[A, B]: Unit = macro impl[A, B]
def foo2[A]: Unit = macro impl[A, Option[Int]]
def impl[A:…

arz.freezy
- 648
- 1
- 6
- 12
0
votes
0 answers
Generating import statements with scala macros
I have the following code:
@mymacro @imports
val _1 = { import scala.collection.mutable.ListBuffer }
@mymacro
val _2 = { val yy: ListBuffer[Int] = ListBuffer.empty }
@mymacro is a scala macro that checks if it has been annotated with the…

michael
- 1
- 1
0
votes
1 answer
Typetree rewritten after type checking
While maintaining the old Scala code written in Scala 2.10.x, something unexpected happened to me when I tried to type check a TypeTree in macros. Look at the following code,
annottees.map(_.tree).toList match {
case q"$mods def…

Sheng
- 1,697
- 4
- 19
- 33
0
votes
1 answer
How to prevent typecheck in StaticAnnotation?
I am creating some macro libraries that reads some information from annotation on the enclosing method.
@info(foo(bar, baz))
def enclosing() = {
myMacro()
}
These information are encoded as foo(bar, baz) in a StaticAnnotation @info.
foo(bar, baz)…

Yang Bo
- 3,586
- 3
- 22
- 35
0
votes
1 answer
Obtaining the realised type for a Scala Class using macros
I have some problems with scala macros and identifying the realised type of a constructor.
Not sure if i am doing something wrong here or what the correct call would be.
From the documentation, it looks like typeSignatureIn should return the correct…

Philipp
- 967
- 6
- 16
0
votes
1 answer
Passing type parameter to scala meta macro/annotations
package scalaworld.macros
import scala.meta._
class Argument(arg: Int) extends scala.annotation.StaticAnnotation {
inline def apply(defn: Any): Any = meta {
println(this.structure)
val arg = this match {
// The argument needs to be…

Bate
- 23
- 8
0
votes
1 answer
Scala Macro - error referencing class symbol "not found: value "
I'm trying to create a Scala macro that generates code like:
val x = new com.foo.MyClass()
where com.foo.MyClass is definitely on the classpath at compile time and run time in the project using the macro.
I'm using the following c.Tree to generate…

Charles Capps
- 389
- 3
- 11
0
votes
1 answer
Why does the Scala Macro for case class copy fail?
I have about 24 Case classes that I need to programatically enhance by changing several common elements prior to serialization in a datastore that doesn't support joins. Since case classes don't have a trait defined for the copy(...) constructor, I…

Steven Fines
- 467
- 4
- 14
0
votes
1 answer
Generate case classes serializer and deserializer implicitly using play-json
I'm using play-json to map Json to case classes or enums. I'm looking for a smart way of creating Formats implicitly, since my project contains many types definitions.
At the moment I created a simple function to generate Formats for Enums:
def…

WalkerTR
- 23
- 5
0
votes
2 answers
Expand list of values into cases
Here is what I have:
sealed abstract class Codes(list: List[String])
object UVWCodes extends Codes(List("U", "V", "W"))
object XYZCodes extends Codes(List("X", "Y", "Z"))
I would like to use macros to expand the listed values into:
parse(str:…

pgrandjean
- 676
- 1
- 9
- 19
0
votes
1 answer
Scala Export/import macro project
I´ve been googling but I could not find a good documentation.
I create a project with an entry API using macros, but now since I cannot use it even from my own project I need to export it.
Anybody please can point me to a good documentation/blog…

paul
- 12,873
- 23
- 91
- 153
0
votes
1 answer
scala AST - what IS a string constant literal and how do I find out?
Consider the following snippet
object Main {
def main(args:Array[String]): Unit ={
import Debugger.debug
debug("Hello World")
val x = 0
debug(x)
debug(1)
}
}
I want this to print
Hello World
x = 0
1
by making use of a…

User1291
- 7,664
- 8
- 51
- 108
0
votes
0 answers
Unfold/desugar scala macro
I am trying to write my own scalajs-react components by wrapping existing JS-react components, so that they can be used from scala.js.
I am trying to understand how to do that by understanding how it is done here.
The problem is that I don't really…

jhegedus
- 20,244
- 16
- 99
- 167