2

I was debugging some code related to Scala macros.

m is a def macro, which takes a function as its parameter:

def m(f: T => Boolean) = macro xxx

There is another function g: T => Boolean. I found different behaviors by passing different lambda expressions to m:

  1. (x: T) => g(x)
  2. (x: T) => (() => g(x))()

Is there a proper way to debug such cases? If I'm not mistaken, the parameters are expanded to AST and passed to the macro at compile time. How can I debug the compiled AST?

Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
  • 1
    https://stackoverflow.com/questions/11055210/whats-the-easiest-way-to-use-reify-get-an-ast-of-an-expression-in-scala and https://stackoverflow.com/questions/11677609/how-do-i-print-an-expanded-macro-in-scala might be helpful. – Alexey Romanov Nov 28 '17 at 17:21
  • I'm afraid those examples weren't clear to me. I am seeking to do the same thing as this poster. Inside a quasiquote I want to invoke f. The obvious thing of $f(someT) didn't work. How can you unscramble the AST to behave like a function call (i.e. pass something to it and invoke it)? – Greg Jan 22 '19 at 04:07

0 Answers0