Questions tagged [scala-quasiquotes]

In Scala, quasiquotes are shipped in the official Scala distribution as part of scala-reflect.jar

Read also: http://docs.scala-lang.org/overviews/quasiquotes/intro.html

91 questions
4
votes
1 answer

scala macro Unknown type error with java bean class creation

I created the following code snippet for use as an encode generator for scala type to java type. object Macros { def encode[A <: Product, B](value:A):B = macro MacrosImpl.encode_impl[A, B] } class MacrosImpl(val c:Context) { import…
tiran
  • 2,389
  • 1
  • 16
  • 28
4
votes
1 answer

What's the right way to generate a companion class de novo using quasiquotes?

I'm experimenting with macro annotations in Scala 2.10.3 using macroparadise 2.0.0-M3. I am trying to understand how to use quasiquotes to generate a companion object to an annotated class. What I have found so far is how to generate a companion…
dstu
  • 43
  • 2
4
votes
3 answers

How to match a `universe#Type` via quasiquotes or deconstructors?

I have a type resultType of Context.this.type#c#universe#Type. I need to match it against Unit type. I tried resultType match { case q"Unit" => ... } but I suppose that Unit is just a string literal here that obviously do not match. How to match…
Alexander Myltsev
  • 459
  • 1
  • 3
  • 13
3
votes
1 answer

Dependent type seems to “not work” when generated by Scala macro

Apologies for the handwavey title. I’m not entirely sure how to phrase the question succinctly, since I’ve never encountered something like this before. Background info: I have the following trait, where the type U is meant to hold a Shapeless…
Dan Li
  • 866
  • 1
  • 7
  • 19
3
votes
0 answers

Distinguishing Tuple1 in quasiquote matching

Suppose I want a macro that takes an expression and returns the arity if it's a tuple literal. Something like this works for tuples but returns Some(1) instead of None for everything else: import scala.reflect.macros.blackbox.Context class…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
3
votes
2 answers

scala - insert value into quasiquote

Unfortunately, the most intuitive way, val world = "Earth" val tree = q"""println("Hello $world")""" results in Error:(16, 36) Don't know how to unquote here val tree = q"""println("Hello $world")""" ^ because $ within…
User1291
  • 7,664
  • 8
  • 51
  • 108
3
votes
0 answers

Scala macro to generate new instance of class with dependency injection of trait with abstract fields

Update: Modified the code to use macro annotation, but still missing something The following code works (question below): object MyTypes { trait RealType class Container[RT <: RealType] { this: RT => } trait SomeRealType extends…
3
votes
2 answers

Scala: Dynamically generating match clauses for case classes

I want to use the power of Scala's pattern matching within a set of `condition-action' rules. These rules are not known in advance, but rather are generated at runtime according to some complex critera. The algorithmic generation mechanism can be…
NietzscheanAI
  • 966
  • 6
  • 16
3
votes
0 answers

Performance and caching of generated code in Scala

I need to generate an implementation of a trait at runtime, then execute a known method on an instance of the trait. In this example I'm running A's a method: import reflect.runtime._, universe._, tools.reflect.ToolBox package p { trait A { def…
devth
  • 2,738
  • 4
  • 31
  • 51
3
votes
1 answer

How to inject quasi quotes array

I have an array of quasi quotes called definitions which I want to inject to the quasi quote tree. How do I go about doing this? private def generateDaoComponent(files: Array[File]) = { val file = createNewFile(compDirectory) val…
user1187135
3
votes
3 answers

Conflicting cross-version suffixes in: org.scalamacros:quasiquotes

I am trying to use scala-pickling in one of my projects. I tried to mimic the build file of macroid which seems to use pickling too but I keep getting this error on sbt test: [error] Modules were resolved with conflicting cross-version suffixes in…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
3
votes
1 answer

What is the type of quasiquote that matched type parameters?

I have a quoasiquote matcher where q"someMethod[$ts]()" where def someMethod[I <: shapeless.HList]()". Printing ts gives: List(shapeless.HNil) or, e.g. List(String, Int) Then I try to assign: val types: List[scala.reflect.api.Types.Type] =…
Alexander Myltsev
  • 459
  • 1
  • 3
  • 13
3
votes
1 answer

Resolving the dependency of Scala Macros and Compiler Framework in SBT

I am trying to write a framework to make writing Scala compiler plugins easier, what I am doing is writing a framework on top of the Scala quasiquotes. So my project depends on macros from macro-paradise and both scala-compiler and scala-reflect…
2
votes
1 answer

Using freshName as a parameter without explicitly specifying type

I'm trying to use freshName as a parameter name in the following macro: I. def test: Unit = macro implTst def implTst(c: blackbox.Context): c.Expr[Unit] = { import c.universe._ def withImplicitsM(exprs: List[c.Tree], expr: c.Tree): c.Tree = …
Some Name
  • 8,555
  • 5
  • 27
  • 77
2
votes
1 answer

Storing long quasiquote matchers in a variable

I'm trying to avoid repetition of long quasiquotes in matches. So, I'd like to convert this: def appendTree(clazz: ClassDef, tree: Tree): ClassDef = clazz match { case q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends {…
ofo
  • 1,160
  • 10
  • 21