Skip to content

Commit b5fd1b9

Browse files
committed
Marks macros when top level splices are created
1 parent 59352c8 commit b5fd1b9

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,6 @@ object Applications {
217217
class ExtMethodApply(app: Tree)(implicit @constructorOnly src: SourceFile)
218218
extends IntegratedTypeArgs(app)
219219

220-
/** If we are in an inline method but not in a nested quote, mark the inline method
221-
* as a macro.
222-
*/
223-
def handleMeta(tree: Tree)(implicit ctx: Context): tree.type = {
224-
import transform.SymUtils._
225-
226-
def markAsMacro(c: Context): Unit =
227-
if (c.owner eq c.outer.owner) markAsMacro(c.outer)
228-
else if (c.owner.isInlineMethod) c.owner.setFlag(Macro)
229-
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
230-
if (tree.symbol.isSplice && StagingContext.level == 0)
231-
markAsMacro(ctx)
232-
tree
233-
}
234220
}
235221

236222
trait Applications extends Compatibility { self: Typer with Dynamic =>
@@ -811,7 +797,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
811797
* or, if application is an operator assignment, also an `Assign` or
812798
* Block node.
813799
*/
814-
def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = handleMeta {
800+
def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
815801

816802
def realApply(implicit ctx: Context): Tree = track("realApply") {
817803
val originalProto = new FunProto(tree.args, IgnoredProto(pt))(this, tree.isContextual)(argCtx(tree))
@@ -955,7 +941,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
955941
val isNamed = hasNamedArg(tree.args)
956942
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
957943
record("typedTypeApply")
958-
handleMeta(typedFunPart(tree.fun, PolyProto(typedArgs, pt)) match {
944+
typedFunPart(tree.fun, PolyProto(typedArgs, pt)) match {
959945
case IntegratedTypeArgs(app) =>
960946
app
961947
case _: TypeApply if !ctx.isAfterTyper =>
@@ -977,7 +963,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
977963
}
978964
if (typedFn.tpe eq TryDynamicCallType) tryDynamicTypeApply()
979965
else assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs)
980-
})
966+
}
981967
}
982968

983969
/** Rewrite `new Array[T](....)` if T is an unbounded generic to calls to newGenericArray.

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ class Typer extends Namer
449449
}
450450
case qual =>
451451
if (tree.name.isTypeName) checkStable(qual.tpe, qual.sourcePos)
452-
val select = Applications.handleMeta(
453-
checkValue(assignType(cpy.Select(tree)(qual, tree.name), qual), pt))
452+
val select = checkValue(assignType(cpy.Select(tree)(qual, tree.name), qual), pt)
454453
if (select.tpe ne TryDynamicCallType) ConstFold(checkStableIdentPattern(select, pt))
455454
else if (pt.isInstanceOf[FunOrPolyProto] || pt == AssignProto) select
456455
else typedDynamicSelect(tree, Nil, pt)
@@ -2027,8 +2026,17 @@ class Typer extends Namer
20272026
tree.withType(UnspecifiedErrorType)
20282027
}
20292028
}
2030-
else
2029+
else {
2030+
if (StagingContext.level == 0) {
2031+
// Mark the first inline method from the context as a macro
2032+
def markAsMacro(c: Context): Unit =
2033+
if (c.owner eq c.outer.owner) markAsMacro(c.outer)
2034+
else if (c.owner.isInlineMethod) c.owner.setFlag(Macro)
2035+
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
2036+
markAsMacro(ctx)
2037+
}
20312038
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext).withSpan(tree.span)
2039+
}
20322040
}
20332041
}
20342042

0 commit comments

Comments
 (0)