scala-macro-paradise

enable macro paradise to expand macro annotations

孤人 提交于 2021-02-19 06:42:38
问题 I wanted to check some examples with annotations in macro paradise and I am getting the error, as is specified in: this example I have related the projects, the other scala macros (not with annotations) are working very well. I have included the library paradise_2.11.6-2.1.0-M5 (in both projects also :( ). I think, I do not get what means with *to enable* . !? bthw, I am using Scala IDE in Eclipse. 回答1: By enable, I meant adding it as a compiler plugin, as e.g. in https://github.com

Scala macro can't find my java class

家住魔仙堡 提交于 2020-01-05 03:54:13
问题 I'm creating a scala macro to automatically generate case classes from POJOs (in order to make working with avro a little bit nicer). Everything "works" except that the compiler - during macro expansion only - chokes on my java class. If I comment out the call to the macro, everything compiles fine. My question is: how do I generate code in the macro such that the compiler resolves my own java classes? Example error message: [info] Compiling 1 Scala source to /Users/marcin/development/repos

new-style (“inline”) macros require scala.meta

穿精又带淫゛_ 提交于 2020-01-03 10:21:16
问题 I just updated to scala meta 2.0.0-M1 and with the latest scala 2.12.3 and now macros no longer compile. The only change i made was to change the meta version from 1.8.0 to 2.0.0-M1. ERROR: new-style ("inline") macros require scala.meta Does anybody know if there is a quick work around for this? I was hoping to start playing with some of the semantic improvements. 回答1: scalameta/paradise currently supports scalameta 1.8.0 only, not 2.0.0-M1. The new improvements in the semantic api are not

What does it mean when macro annotation cannot be used in the same compilation that defines it?

你离开我真会死。 提交于 2019-12-23 12:38:19
问题 I am curious about this statement: Error:(3, 18) ...another possibility is that you try to use macro annotation in the same compilation run that defines it) I tried googling and found this: Finally, remember that using macros requires compilation to happen in two steps: first, compile the macros, then compile the code where the macros are used. This is necessary so that your macros can be run before the rest of your code is compiled. For example if you use SBT, you can configure Build.scala

Provide implicits for all subtypes of sealed type

老子叫甜甜 提交于 2019-12-23 03:41:21
问题 In my application I have multiple case classes and objects which are part of sealed trait hierarchy. I use them as messages in Akka. Those classes need to be converted to user friendly form before sending through websocket. Previously I used big pattern match to convert them in single place, but as number of types grows I would like to use implicit conversion: object Types { sealed trait Type case object SubType1 extends Type case object SubType2 extends Type case object SubType3 extends Type

Provide implicits for all subtypes of sealed type

蓝咒 提交于 2019-12-23 03:41:08
问题 In my application I have multiple case classes and objects which are part of sealed trait hierarchy. I use them as messages in Akka. Those classes need to be converted to user friendly form before sending through websocket. Previously I used big pattern match to convert them in single place, but as number of types grows I would like to use implicit conversion: object Types { sealed trait Type case object SubType1 extends Type case object SubType2 extends Type case object SubType3 extends Type

Scala macro to print code?

孤者浪人 提交于 2019-12-18 05:01:49
问题 I want to do something like this: def assuming[A](condition: => Boolean)(f: => A): A = { require(condition, /* print source-code of condition */) f } Sample usage: def fib(n: Int) = n match { // yes, yes, I know this is not efficient case 0 => 0 case 1 => 1 case i => assuming(i > 0) { fib(i-1) + fib(i-2) } } Now, for example, if you call fib(-20) , I want it to throw an exception with a message like Assertion failed: -20 > 0 or Assertation failed: i > 0 回答1: Dude, isn't an assert macro one of

Scala macro to print code?

不想你离开。 提交于 2019-12-18 05:01:06
问题 I want to do something like this: def assuming[A](condition: => Boolean)(f: => A): A = { require(condition, /* print source-code of condition */) f } Sample usage: def fib(n: Int) = n match { // yes, yes, I know this is not efficient case 0 => 0 case 1 => 1 case i => assuming(i > 0) { fib(i-1) + fib(i-2) } } Now, for example, if you call fib(-20) , I want it to throw an exception with a message like Assertion failed: -20 > 0 or Assertation failed: i > 0 回答1: Dude, isn't an assert macro one of

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

我的梦境 提交于 2019-12-14 02:24:27
问题 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: String): Unit = c.info(c.enclosingPosition, msg, force=true) def rawInfo(name: String, obj: Any): Unit = info(name + " = " + showRaw(obj)) } methodsIn(body) foreach { dd => //dd: DefDef val name = dd.name.toString log.rawInfo(name, dd) log.rawInfo(name + ".rhs

How to Typecheck a DefDef

笑着哭i 提交于 2019-12-12 11:47:06
问题 Within an annotation Macro, I'm enumerating members of a class and want the types of the methods that I find. So I happily iterate over the body of the class, and collect all the DefDef members. ... which I can't typecheck. For each DefDef I've tried wrapping it in an Expr and using actualType . I've tried duplicating the thing and transplanting it into an ad-hoc class (via quasiquotes). I've tried everything else I can think of :) The best I can get is either NoType or Any , depending on the