@@ -372,12 +372,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
372
372
* from its `originalOwner`, and, if it comes from outside the inlined method
373
373
* itself, it has to be marked as an inlined argument.
374
374
*/
375
- def integrate (tree : Tree , originalOwner : Symbol )(implicit ctx : Context ): Tree = {
376
- val result = tree.changeOwner(originalOwner, ctx.owner)
377
- if (! originalOwner.isContainedIn(inlinedMethod))
378
- Inlined (EmptyTree , Nil , result).withSpan(tree.span)
379
- else result
380
- }
375
+ def integrate (tree : Tree , originalOwner : Symbol )(implicit ctx : Context ): Tree =
376
+ tree.changeOwner(originalOwner, ctx.owner)
381
377
382
378
def tryConstValue : Tree =
383
379
ctx.typeComparer.constValue(callTypeArgs.head.tpe) match {
@@ -418,6 +414,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
418
414
419
415
val inlineCtx = inlineContext(call).fresh.setTyper(inlineTyper).setNewScope
420
416
417
+ def inlinedFromOutside (tree : Tree )(span : Span ): Tree =
418
+ Inlined (EmptyTree , Nil , tree)(ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
419
+
421
420
// A tree type map to prepare the inlined body for typechecked.
422
421
// The translation maps references to `this` and parameters to
423
422
// corresponding arguments or proxies on the type and term level. It also changes
@@ -438,7 +437,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
438
437
tree.tpe match {
439
438
case thistpe : ThisType =>
440
439
thisProxy.get(thistpe.cls) match {
441
- case Some (t) => ref(t).withSpan(tree.span)
440
+ case Some (t) =>
441
+ val thisRef = ref(t).withSpan(call.span)
442
+ inlinedFromOutside(thisRef)(tree.span)
442
443
case None => tree
443
444
}
444
445
case _ => tree
@@ -449,12 +450,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
449
450
if (tree.name == nme.WILDCARD ) tree.span // From type match
450
451
else if (tree.symbol.isTypeParam && tree.symbol.owner.isClass) tree.span // TODO is this the correct span?
451
452
else paramSpan(tree.name)
453
+ val inlinedCtx = ctx.withSource(inlinedMethod.topLevelClass.source)
452
454
paramProxy.get(tree.tpe) match {
453
455
case Some (t) if tree.isTerm && t.isSingleton =>
454
- t.dealias match {
455
- case tp : ConstantType => Inlined (EmptyTree , Nil , singleton(tp).withSpan(argSpan)).withSpan(tree.span)
456
- case tp => singleton(tp).withSpan(argSpan)
457
- }
456
+ val inlinedSingleton = singleton(t).withSpan(argSpan)
457
+ inlinedFromOutside(inlinedSingleton)(tree.span)
458
458
case Some (t) if tree.isType =>
459
459
TypeTree (t).withSpan(argSpan)
460
460
case _ => tree
@@ -467,7 +467,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
467
467
468
468
// Apply inliner to `rhsToInline`, split off any implicit bindings from result, and
469
469
// make them part of `bindingsBuf`. The expansion is then the tree that remains.
470
- val expansion = inliner.transform(rhsToInline).withSpan(call.span)
470
+ val expansion = inliner.transform(rhsToInline)
471
471
472
472
def issueError () = callValueArgss match {
473
473
case (msgArg :: rest) :: Nil =>
@@ -1159,8 +1159,17 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1159
1159
assert(level == 0 )
1160
1160
val inlinedFrom = enclosingInlineds.last
1161
1161
val evaluatedSplice = Splicer .splice(body, inlinedFrom.sourcePos, MacroClassLoader .fromContext)(ctx.withSource(inlinedFrom.source))
1162
+
1163
+ val inlinedNormailizer = new TreeMap {
1164
+ override def transform (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
1165
+ case Inlined (EmptyTree , Nil , expr) if enclosingInlineds.isEmpty => transform(expr)
1166
+ case _ => super .transform(tree)
1167
+ }
1168
+ }
1169
+ val normalizedSplice = inlinedNormailizer.transform(evaluatedSplice)
1170
+
1162
1171
if (ctx.reporter.hasErrors) EmptyTree
1163
- else evaluatedSplice .withSpan(span)
1172
+ else normalizedSplice .withSpan(span)
1164
1173
}
1165
1174
1166
1175
}
0 commit comments