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

Scala Macros: Method overloading

I have a converter function that creates a case class object from JSON, which is defined as follows: object JSONConverter { import language.experimental.macros def modelFromJson[T <: Model](json: JsValue):T = macro modelFromJson_impl[T] } I'm…
Emre
  • 1,023
  • 2
  • 9
  • 24
0
votes
1 answer

Macro access to members of object where macro is defined

Say I have a trait Foo that I instantiate with an initial value i val foo = new Foo(6) // class Foo(i: Int) and I later call a secondMethod that in turn calls myMacro foo.secondMethod(7) // def secondMethod(j: Int) = macro myMacro then, how can…
Marc Grue
  • 5,865
  • 3
  • 16
  • 23
0
votes
0 answers

Scala macros and code generation

Given the simple example source I need to be able to create a copy constructor and implicit conversion method. Can somebody please advice how to achieve this with Scala 2.10 and new macros feature? import java.util.UUID object Sample { case…
jdevelop
  • 12,176
  • 10
  • 56
  • 112
0
votes
1 answer

enhanced assert scala macro

I’ve come across some annoying problems when using asserts where there is either no good information available: why did it fails, and what the assert was about the assert information is buried under a sea of unneeded information like too many…
Eric Mariacher
  • 341
  • 1
  • 8
0
votes
2 answers

Universal copy function as a Macro

I'd really like to use case classes' copy feature in my project, but unfortunately I also need inheritance, which doesn't work well with case classes. So, I'm wondering if it's possible to write a macro which will generate a method for creating…
Lukasz Gieron
  • 276
  • 2
  • 12
-1
votes
0 answers

How can I recursively call a function from with a Scala 3 macro Expr?

I have a macro impl in which I have a function I want to call recursively for nested behavior. I've simplified a trivial count-down example to show the desired effect: import scala.quoted.* import quoted.Quotes // Desired recursive effect: // // …
Greg
  • 10,696
  • 22
  • 68
  • 98
-1
votes
1 answer

Get sequence of types from HList in macro

Context: I'm trying to write a macro that is statically aware of an non-fixed number of types. I'm trying to pass these types as a single type parameter using an HList. It would be called as m[ConcreteType1 :: ConcreteType2 :: ... :: HNil](). The…
gandaliter
  • 9,863
  • 1
  • 16
  • 23
-1
votes
2 answers

Macros support in tooling

https://www.reddit.com/r/Kotlin/comments/7hoytl/kotlin_team_ama_ask_us_anything/dqt56nv/ Traditional macros are very hard to support well in the tooling In Java we already have Lombok @Data what generate methods, almost the same as…
Axel
  • 125
  • 1
  • 12
-1
votes
1 answer

scala rename case class property dynamically

I have an object object Helper{ val fieldName = "fooBar } which provides the name for a field. And a case class case class BarBaz(fieldOne:Int, fieldTwo:String) But instead of fieldTwo, I would like to refer to Helper.fieldname for the parameter…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
1 2 3
51
52