c.Tree in macro bundle method result type does not compile, while Tree does
netvl opened this issue · comments
Vladimir Matveev commented
Consider this code:
package example
import scala.reflect.macros.whitebox
import scala.language.experimental.macros
object Example {
def generate[T] = macro ExampleBundle.doSomethingImpl[T]
}
@macrocompat.bundle
class ExampleBundle(val c: whitebox.Context) {
import c.universe._
//def doSomethingImpl[T: WeakTypeTag]: Tree = ???
def doSomethingImpl[T: WeakTypeTag]: c.Tree = ???
}
It does not compile:
> compile
[info] Compiling 1 Scala source to /home/netvl/dev/lang/scala/macro-compat-tree-problem/target/scala-2.10/classes...
[error] /home/netvl/dev/lang/scala/macro-compat-tree-problem/src/main/scala/example.scala:7: value doSomethingImpl is not a member of object example.ExampleBundle
[error] def generate[T] = macro ExampleBundle.doSomethingImpl[T]
[error] ^
According to -Ymacro-debug-lite output, the macro bundle method has no corresponding forwarding method in the generated companion object. However, if you uncomment the top line instead of the bottom one:
def doSomethingImpl[T: WeakTypeTag]: Tree = ???
//def doSomethingImpl[T: WeakTypeTag]: c.Tree = ???
then everything compiles correctly.
It seems that this happens because of too naive resolution of Tree
type during the generation of the forwarding methods.