Can't access Parent's Members while dealing with Macro Annotations

前端 未结 1 500
情深已故
情深已故 2020-12-01 17:43

I am kind of blocked with the following (macro annotation) situation. Suppose I have an annotation called @factory which aims to generate an appl

相关标签:
1条回答
  • 2020-12-01 18:02

    Trees that go into macro annotation arguments are purposefully untyped. However running c.typeCheck(q"(??? : <tree that represents the parent>)").tpe will provide the missing information. Don't forget to duplicate that tree before typechecking, because c.typeCheck mutates the tree in place, which might be undesireable.

    In case when both parent and child are declared in the same non-toplevel scope, there will be a problem of typeCheck not seeing the parent, as c.typeCheck's in macro annotations are performed in parent lexical scope, so that annotations don't get to see half-constructed scopes. Something similar has been reported here: https://github.com/aztek/scala-workflow/issues/2#issuecomment-23947943.

    The decision to exclude current scope from typechecking is not a final one. This week I'll be thinking a bit more about how macro annotations should interact with enclosing scopes, and will probably change it to do what you would like it to do. I'd do the change right now, but I need to make sure there won't be any insane behaviour arising from that change.

    0 讨论(0)
提交回复
热议问题