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

Macros: Check class attributes in compilation time

I´m using Macros, and I would like to check in compilation time, if an instance class created contains all attribute passed in the constructor, or if one of them are null, and if that's the case fail in compilation time instead in runtime. I´ve been…
paul
  • 12,873
  • 23
  • 91
  • 153
0
votes
1 answer

Use scala macros to copy method from class to companion object

I'll get straight to the business. Let's say that I have the following trait definition: trait Routable{ def routing(): String } And I'm defining the following class: case class MyEvent(name: String, age: Int) extends Routable{ override…
user1396033
  • 215
  • 3
  • 11
0
votes
1 answer

scala macro how to convert `HList` to function args

For below types type HFunc = (Int :: String :: HNil) => Int type Func = (Int, String) => Int I try to convert Func to HFunc val funExpr: Tree = ??? val hlistType = ??? val hfuncName = c.freshName("hfunc") q""" def $hfuncName(t:…
jilen
  • 5,633
  • 3
  • 35
  • 84
0
votes
2 answers

How to efficiently traverse recursive case-class trees

I want to create a macro that generates a recursive traversal of a tree of case class instances similar to the visitor pattern. The generated code should recurse for all fields whose type is derived from one of multiple base types. I thought about…
0
votes
1 answer

How to pattern match types in Scala macros?

I have a method in my project with macros (whitebox), trying to verify and extract type arguments from a return type of a MethodSymbol. Here is the code (placed inside some class with import c.universe._): private object ImplMethod { def apply(m:…
jenda
  • 336
  • 2
  • 3
0
votes
1 answer

Passing parameters to scalameta paradise macro

I am trying to create a macro annotation but I need to pass it parameters. class ToPojo(param1: String, param2: String) extends StaticAnnotation { inline def apply(defn: Any): Any = meta { ... } } which is used as @ToPojo("p1",…
Vojtech Letal
  • 2,168
  • 3
  • 13
  • 17
0
votes
1 answer

Inexplicable type mismatch using Scala macros

I'm completely baffled by the following behavior of macros: The problem: I'm trying to write a query engine for a model built on case classes, where the user only has to specify the fields against which he wishes to match. The current approach:…
0
votes
3 answers

Generate a function to instantiate a case class with default values using Scala's macro

There is a case class that looks like this: case class User( id: Long, name: String, email: String) I want to use Scala macro to generate a function like below: def makeUser( id: Long = 1L, name: String = "some name", email:…
Tanin
  • 1,853
  • 1
  • 15
  • 20
0
votes
1 answer

Conditionally generating implicits in scala

I am working on a system of chained implicit functions, which is similar to the simplified example below. The test c1.payload == c2.payload represents a test I need to do that is not in "type-space"; I had expected that I would drop into a macro for…
eje
  • 945
  • 11
  • 22
0
votes
0 answers

Scala macros evaluate Enumeration values

Given an Enumeration like this: object Enum1 extends Enumeration { val value1, value2 = Value val value3 = Value("value3Name") val notNewAValue = value3 } And an object like this: @MyMacro object MacroObject How could I access the values…
dreigada
  • 83
  • 1
  • 7
0
votes
0 answers

How to force methods run in `ExecutionContext`?

How can I run methods from inside a specific ExecutionContext only? For example, consider this code: trait SomeTrait { private var notThreadSafe = 0 // mutable var! def add(i: Int) = ??? def subtract(i: Int) = ??? } This code is only correct…
VasiliNovikov
  • 9,681
  • 4
  • 44
  • 62
0
votes
0 answers

Read annotations of a typedef from Scala Macro

Given a wrapper case class which has a set of values of which the types will be typedefs with annotations on them. I want to inspect the types to see whether the annotation is present and what the value is. This is so that I can create a macro that…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
0
votes
2 answers

Instance case class from companion object

I have the following: trait C {} object O { case class Foo(bar: String) extends C } And I would like to instance Foo from a String. Until the moment I have achieved instanciate Foo, but I cannot cast to C. I am using: val ob =…
ie8888
  • 171
  • 1
  • 10
0
votes
1 answer

Scala macros: string literal assigned to a variable does not match

I am using a macro annotation from Spotify's Scio library. I would like to define a variable of String type and annotate like this: val schemaString = """schema here""" @BigQueryType.fromSchema(outputString) class BigQuery This does not compile,…
jamborta
  • 5,130
  • 6
  • 35
  • 55