Can I integrate Cake-Pattern and macros?

I have to integrate some macros in a project that uses a cake template. This template allowed us to avoid other import advantages, so we would like to keep it. Now we are faced with a problem with some experimental macros that we tested outside the trunk. First show a dummy system called Cake:

trait APiece {
  class A
}

trait BPiece { this: APiece => 
  def aMacro(a: A): Unit = () /* macro ??? */
}

trait CPiece { this: APiece with BPiece =>
  def aMacroInvoker = aMacro(new A)
}

class Cake { this: APiece with BPiece with CPiece => }

APiece defines the class, BPiece must be a macro that uses the specific APiece class, and finally CPiece calls the macro. I said that BPiece was supposed to be a macro since I could not code its implementation. I tried several ways, but I always crash with the following error:

"macro implementation must be in statically accessible object"

, , . , ?

+5
1

, .

. : def macro aMacro(a: A): Unit = .... , SIP, ( ) ( , ). , , , , .

, . , - ( ). , :

trait BPiece { this: APiece => 
  def aMacro(a: A): Unit = macro Macros.aMacro
}

, , , , .

- , A , A . - aMacro :

(: 2.10.0-M7, c.TypeTag c.AbsTypeTag; 2.10.0-RC1, c.AbsTypeTag c.WeakTypeTag)

trait BPiece { this: APiece =>
  def aMacro[A](a: A): Unit = macro Macros.aMacro[A]
}

object Macros {
  def aMacro[A: c.TypeTag](c: Context)(a: c.Expr[A]): c.Expr[Unit] = c.literalUnit
}

reify, , A - . , - , , . , , .

+4

All Articles