aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/transform/MacroTransform.scala16
-rw-r--r--src/dotty/tools/dotc/transform/TreeTransform.scala8
2 files changed, 20 insertions, 4 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
diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala
index 2bc733465..8e7c4f6d0 100644
--- a/src/dotty/tools/dotc/transform/TreeTransform.scala
+++ b/src/dotty/tools/dotc/transform/TreeTransform.scala
@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.Symbols.Symbol
+import dotty.tools.dotc.core.Flags.PackageVal
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Decorators._
import scala.annotation.tailrec
@@ -883,7 +884,12 @@ object TreeTransforms {
}
} else tree
- def localContext(owner: Symbol)(implicit ctx: Context) = ctx.fresh.setOwner(owner)
+ // TODO merge with localCtx in MacroTransform
+ // Generally: If we will keep MacroTransform, merge common behavior with TreeTransform
+ def localContext(sym: Symbol)(implicit ctx: Context) = {
+ val owner = if (sym is PackageVal) sym.moduleClass else sym
+ ctx.fresh.setOwner(owner)
+ }
final private[TreeTransforms] def transformNamed(tree: NameTree, info: TransformerInfo, cur: Int)(implicit ctx: Context): Tree =
tree match {