Questions tagged [scala-macro-paradise]

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.

77 questions
1
vote
1 answer

How to get range position from macro annotation?

I'm using macro annotation to instrument code. How can I get the range position of some expressions ? @ScalaKata object SHA { val foo = "foo" val bar = "bar" foo; bar // ... } // result: Map((75, 78) -> "foo", (80, 83) ->…
Guillaume Massé
  • 8,004
  • 8
  • 44
  • 57
1
vote
3 answers

Type safe String interpolation in Scala

Inspired by this, I was wondering if we can have type-safe string interpolations in Scala (maybe using macros)? For example, I want to have something like this def a[A] = ??? val greetFormat = f"Hi! My name is ${a[String]}. I am ${a[Int]} years old"…
1
vote
1 answer

scala quasiquotes convert Tree to AppliedType

I wan to infer an implicit value of an AppliedType, here's what I've done val valueType = accessorTree.returnType val encoderType = tq"DatumEncoder[$valueType]" // returns a Tree val encoder = c.inferImplicitValue(encoderType) // require a Type But…
jilen
  • 5,633
  • 3
  • 35
  • 84
1
vote
1 answer

Why does typecheck return NoType, even when it's calculated a valid symbol?

Following on from: How to Typecheck a DefDef First, some snippets from my macro: object log { def err(msg: String): Unit = c.error(c.enclosingPosition, msg) def warn(msg: String): Unit = c.warning(c.enclosingPosition, msg) def info(msg:…
Kevin Wright
  • 49,540
  • 9
  • 105
  • 155
1
vote
1 answer

Adding extra trait to object using scala macro annotation

I'm on Scala 2.10.3 using Macro Paradise. I have a macro annotation where I'm trying to add a trait to on object, e.g: @MyAnnotation object Foo extends Bar {} After expansion I want something like: object Foo extends Bar with Baz {} Where Baz is a…
user3293336
  • 121
  • 1
1
vote
0 answers

Runtime integer value as a type-level integer (like shapeless.Nat, but not a literal)

I am trying to represent a finite ring ℤ/nℤ with the characteristic being a type-level integer specified at runtime. Would it be possible to have something similar to shapeless.Nat to represent a type-level integer, but without it needing to be a…
0
votes
1 answer

In scala 2.13. How to log information/warning/error reliably in macro?

I'm writing a macro that can log a short message during the compilation, using pattern matching and constant type feature of scala 2.13: class EmitMsg[T, SS <: EmitMsg.EmitLevel] {} object EmitMsg { trait EmitLevel trait Info extends…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
0
votes
1 answer

How do Scala macro typechecks resolve identifiers to types?

I'm trying to create an annotation macro which can only be applied to a certain type. When I run my tests I see a type not found error when the annotation is applied to top level objects only. My macro code: trait Labelled[T] { def label:…
William Carter
  • 1,287
  • 12
  • 19
0
votes
1 answer

Scala macro-based annotation reuse

Consider a Scala macro-based annotation such as @memoise from macmemo. The annotation requires two arguments: a max cache size and a time-to-live, e.g., @memoize(maxSize = 20000, expiresAfter = 2 hours) Say you want to create a @cacheall annotation…
Sim
  • 13,147
  • 9
  • 66
  • 95
0
votes
1 answer

Macro annotation generated companion class's apply method not resolved

I've written a macro annotation processor that generates all the same methods you would get from declaring a case class, but providing hash-consing. It was a bit tricky, but overall I'm very pleased with the results. However, I'm seeing some…
user1063042
  • 273
  • 2
  • 11
0
votes
0 answers

Macros Scala reflect typeSymbol match results in GC overhead limit exceeded

I have a macros plugin that checks if an entity is a case class and then returns all fields in a dot notation. Eg. case class Language(name: String) @Lenses case class Page(a: Language) So the main method would return Seq("language.name") This has…
raul782
  • 479
  • 1
  • 5
  • 15
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

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

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
1 answer

How to pass parameters to annotation with macro expansions

I'm using macros annotation for generating code. I would like to change its behaviour based on additional string parameters. So it would produce different results for same code. I closely followed the guide for macro annotations that covers only…
ayvango
  • 5,867
  • 3
  • 34
  • 73