Skip to content

Commit e219f7e

Browse files
committed
Add workaround to identify after PostTyper Inlined that came macros
1 parent c1e031f commit e219f7e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
224224
super.transform(tree1)
225225
}
226226
case Inlined(call, bindings, expansion) if !call.isEmpty =>
227-
val callTrace = Inliner.inlineCallTrace(call.symbol, call.sourcePos)
227+
val pos = call.sourcePos
228+
val callTrace = Inliner.inlineCallTrace(call.symbol, pos)(ctx.withSource(pos.source))
228229
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(inlineContext(call)))
229230
case tree: Template =>
230231
withNoCheckNews(tree.parents.flatMap(newPart)) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ class YCheckPositions extends Phases.Phase {
5757
}
5858

5959
private def isMacro(call: Tree)(implicit ctx: Context) = {
60-
if (ctx.phase <= ctx.typerPhase.next) call.symbol.is(Macro)
61-
else (call.symbol.unforcedDecls.isEmpty /* bug from exists */ || call.symbol.unforcedDecls.exists(_.is(Macro)) || call.symbol.unforcedDecls.toList.exists(_.is(Macro)))
60+
if (ctx.phase <= ctx.postTyperPhase) call.symbol.is(Macro)
61+
else call.isInstanceOf[Select] // The call of a macro after typer is encoded as a Select while other inlines are Ident
62+
// TODO remove this distinction once Inline nodes of expanded macros can be trusted (also in Inliner.inlineCallTrace)
6263
}
6364

6465
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ object Inliner {
180180
* - the call's position
181181
* in the call field of an Inlined node.
182182
* The trace has enough info to completely reconstruct positions.
183+
* Note: For macros it returns a Select and for other inline methods it returns an Ident (this distinction is only temporary to be able to run YCheckPositions)
183184
*/
184185
def inlineCallTrace(callSym: Symbol, pos: SourcePosition)(implicit ctx: Context): Tree = {
185-
implicit val src = pos.source
186-
Ident(callSym.topLevelClass.typeRef).withSpan(pos.span)
186+
assert(ctx.source == pos.source)
187+
if (callSym.is(Macro)) ref(callSym.topLevelClass.owner).select(callSym.topLevelClass.name).withSpan(pos.span)
188+
else Ident(callSym.topLevelClass.typeRef).withSpan(pos.span)
187189
}
188190
}
189191

0 commit comments

Comments
 (0)