Owen
Owen

Reputation: 39356

How can I use a macro with refined return type inline?

I have a macro:

def f[T]: Any = macro fImpl[T]

 def fImpl[T : context.WeakTypeTag](context: whitebox.Context):
   context.Tree =
 {
   import context.universe._

   q"{ (x: ${weakTypeOf[T]}) => x + 1 }"
 }

When I use it as

f[Int](1)

I see

Error:(26, 6) Any does not take parameters
               f[Int](1)
                     ^

If I split into two statements,

val x = f[Int]

x(1)

there are no errors.

Is there a way that I can use the macro f[Int] as a function, without writing an auxiliary statement?

Upvotes: 2

Views: 152

Answers (1)

Eugene Burmako
Eugene Burmako

Reputation: 13048

This is a bug, which is reported in our issue tracker at https://issues.scala-lang.org/browse/SI-7914.

Upvotes: 2

Related Questions