diff options
Diffstat (limited to 'src/dotty/tools/dotc/transform/MacroTransform.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/MacroTransform.scala | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/transform/MacroTransform.scala b/src/dotty/tools/dotc/transform/MacroTransform.scala index 1ed9e68c2..0ee92bccd 100644 --- a/src/dotty/tools/dotc/transform/MacroTransform.scala +++ b/src/dotty/tools/dotc/transform/MacroTransform.scala @@ -7,6 +7,7 @@ import Phases._ import ast.Trees._ import Contexts._ import Symbols._ +import Flags.PackageVal import Decorators._ /** A base class for transforms. @@ -18,15 +19,24 @@ abstract class MacroTransform extends Phase { override def run(implicit ctx: Context): Unit = { val unit = ctx.compilationUnit - unit.tpdTree = newTransformer.transform(unit.tpdTree) + unit.tpdTree = newTransformer.transform(unit.tpdTree)(ctx.withPhase(transformPhase)) } protected def newTransformer(implicit ctx: Context): Transformer + /** The phase in which the transformation should be run. + * By default this is the phase given by the this macro transformer, + * but it could be overridden to be the phase following that one. + */ + protected def transformPhase(implicit ctx: Context): Phase = this + class Transformer extends TreeMap { - protected def localCtx(tree: Tree)(implicit ctx: Context) = - ctx.fresh.setTree(tree).setOwner(tree.symbol) + protected def localCtx(tree: Tree)(implicit ctx: Context) = { + val sym = tree.symbol + val owner = if (sym is PackageVal) sym.moduleClass else sym + ctx.fresh.setTree(tree).setOwner(owner) + } /** The current enclosing class * @pre We must be inside a class |