Questions tagged [scala-macros]

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.

774 questions
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
0
votes
1 answer

scala proxy macro, issue converting method args to values

I am trying to write a proxy macro using scala macros. I want to be able to proxy a trait X and return instances of X that invoke a function for all methods of X. Here is what I did so far. Say we want to proxy the trait TheTrait (which is defined…
kostas.kougios
  • 945
  • 10
  • 21
0
votes
0 answers

use scala macro annotation to create type and method definition at the same level

I created a macro annotation to be used together with another macro to transform case classes into records with dynamic, typed method…
cedric
  • 351
  • 4
  • 13
0
votes
1 answer

Deferring implicit resolution in macros

So, lets say I have a few things before hand: case class M[A](val value: A) { def apply(as: M[A]*) = macro applyImpl[A] } def tpAware(implicit ev: Context[A]): M[A] val ma: M[X] = ??? I want to do: ma(tpAware) Where applyImpl is defined…
pfn
  • 1,820
  • 12
  • 11
0
votes
1 answer

Calling function with implicit parameter from quasioquote

For some reason every time I try to call a function with an implicit parameter from quasiquotes, it fails with Can't unquote x.universe.Tree, consider providing an implicit instance of Liftable[x.universe.Tree] What's wrong with that? Am I not…
0
votes
0 answers

Convert scala collections in nested case class to java equivalent

I have some case classes: case class Address(street : String, state : String, zip : Option[Int]) case class Person(name : String, address : Option[Address], children : Seq[Person]) and a function that returns one of these classes: def getPerson()…
mushroom
  • 6,201
  • 5
  • 36
  • 63
0
votes
2 answers

Passing type Parameter to reify while implementing a scala macro

Going from the following macro implementation, which is working as expected, i would like to remove the hard coded Account and replace it with a variable beeing passed as type parameter T:c.WeakTypeTag to the macro by the caller. how should the…
Bate
  • 23
  • 8
0
votes
1 answer

Scala macros Type or Symbol lifted

I'm trying to use the fields of a type in a macro, and pass the symbol or typesigs for the fields to a method so I can do some operations that require concrete information about the type. I have code like this (played about with variations): object…
sksamuel
  • 16,154
  • 8
  • 60
  • 108
0
votes
1 answer

Generate a new value in Scala AST

I'm using APIs to reconstruct the scala AST during compiling. I want to change an "Apply" AST like a(1) into an "Assign and Return" Block { val newvalue = a(1) newvalue } And here's my code for generating a new value in AST: val newVal : Tree =…
user5279007
  • 255
  • 2
  • 6
0
votes
1 answer

How to use cq in quasi quote to return the matched pattern

I am trying to write this case authorDao: AuthorDao => authorDao so that it returns the subclass of Dao itself. When I use this quasi quote: val daoType = TypeName(daoName) val caseTerm = TermName(daoName.toLowerCase) cases.append(cq"$caseTerm:…
user1187135
0
votes
0 answers

Passing & validating multiple values to Scala macro

So, I am new to macros in Scala and am having some difficulty with my current objective. I have a class that performs Json parsing of case classes. If the given case class has fields that are of type Enumeration, an implicit array of those…
Jake Sankey
  • 4,977
  • 12
  • 39
  • 53
0
votes
1 answer

Debug macro annotation in Intellij

While debuging macro annotation IntelliJ throws this error: test\UseMacro.scala:7: error: macro annotation could not be expanded (the most common reason for that is that you need to enable the macro paradise plugin; another possibility is that you…
Daryl
  • 644
  • 1
  • 9
  • 20
0
votes
0 answers

Scala IDE 4.1 and SBT

We have a project that uses Scala macros. Scala IDE 4.1 supports Scopes to ease compilation of projects with macros. However, when I use sbt eclipse, the generated project does not show macros as a source folder and does not create separate outputs…
Wickoo
  • 6,745
  • 5
  • 32
  • 45
0
votes
1 answer

Writing Macro for Positive Integers

Given the following types: sealed trait PosIntCheckResult case class LteZero(x: Int) extends PosIntCheckResult case object NotConstant extends PosIntCheckResult I'm trying to write a macro that checks whether the given Int is greater than 0. import…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
0 answers

Can I add class fields dynamically using macros?

I'm new to Scala macros, so sorry if this is an obvious question. I wonder if the following is even possible before I dig in deeper. Let's say I have a class named DynamicProperties Is it possible to add members to the class based on something like…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276