Skip to content

Commit 429103e

Browse files
committed
Remove IdentityDenotTransformer from MacroTransform
1 parent 8c30d37 commit 429103e

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

compiler/src/dotty/tools/dotc/transform/Inlining.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer
1616

1717

1818
/** Inlines all calls to inline methods that are not in an inline method or a quote */
19-
class Inlining extends MacroTransform with IdentityDenotTransformer {
20-
thisPhase =>
19+
class Inlining extends MacroTransform {
2120

2221
import tpd._
2322

@@ -79,7 +78,7 @@ class Inlining extends MacroTransform with IdentityDenotTransformer {
7978
&& StagingContext.level == 0
8079
&& MacroAnnotations.hasMacroAnnotation(tree.symbol)
8180
then
82-
val trees = new MacroAnnotations(thisPhase).expandAnnotations(tree)
81+
val trees = (new MacroAnnotations).expandAnnotations(tree)
8382
val trees1 = trees.map(super.transform)
8483

8584
// Find classes added to the top level from a package object

compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.util.control.NonFatal
2323

2424
import java.lang.reflect.InvocationTargetException
2525

26-
class MacroAnnotations(thisPhase: DenotTransformer):
26+
class MacroAnnotations:
2727
import tpd.*
2828
import MacroAnnotations.*
2929

@@ -82,8 +82,8 @@ class MacroAnnotations(thisPhase: DenotTransformer):
8282
case (prefixed, newTree :: suffixed) =>
8383
allTrees ++= prefixed
8484
insertedAfter = suffixed :: insertedAfter
85-
prefixed.foreach(checkAndEnter(_, tree.symbol, annot))
86-
suffixed.foreach(checkAndEnter(_, tree.symbol, annot))
85+
prefixed.foreach(checkMacroDef(_, tree.symbol, annot))
86+
suffixed.foreach(checkMacroDef(_, tree.symbol, annot))
8787
newTree
8888
case (Nil, Nil) =>
8989
report.error(i"Unexpected `Nil` returned by `(${annot.tree}).transform(..)` during macro expansion", annot.tree.srcPos)
@@ -118,17 +118,15 @@ class MacroAnnotations(thisPhase: DenotTransformer):
118118
val quotes = QuotesImpl()(using SpliceScope.contextWithNewSpliceScope(tree.symbol.sourcePos)(using MacroExpansion.context(tree)).withOwner(tree.symbol.owner))
119119
annotInstance.transform(using quotes)(tree.asInstanceOf[quotes.reflect.Definition])
120120

121-
/** Check that this tree can be added by the macro annotation and enter it if needed */
122-
private def checkAndEnter(newTree: DefTree, annotated: Symbol, annot: Annotation)(using Context) =
121+
/** Check that this tree can be added by the macro annotation */
122+
private def checkMacroDef(newTree: DefTree, annotated: Symbol, annot: Annotation)(using Context) =
123123
val sym = newTree.symbol
124124
if sym.isType && !sym.isClass then
125125
report.error(i"macro annotation cannot return a `type`. $annot tried to add $sym", annot.tree)
126126
else if sym.owner != annotated.owner && !(annotated.owner.isPackageObject && (sym.isClass || sym.is(Module)) && sym.owner == annotated.owner.owner) then
127127
report.error(i"macro annotation $annot added $sym with an inconsistent owner. Expected it to be owned by ${annotated.owner} but was owned by ${sym.owner}.", annot.tree)
128128
else if annotated.isClass && annotated.owner.is(Package) /*&& !sym.isClass*/ then
129129
report.error(i"macro annotation can not add top-level ${sym.showKind}. $annot tried to add $sym.", annot.tree)
130-
else if !sym.is(Module) then // To avoid entering it twice
131-
sym.enteredAfter(thisPhase)
132130

133131
object MacroAnnotations:
134132

0 commit comments

Comments
 (0)