@@ -372,12 +372,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
372372 * from its `originalOwner`, and, if it comes from outside the inlined method
373373 * itself, it has to be marked as an inlined argument.
374374 */
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)
381377
382378 def tryConstValue : Tree =
383379 ctx.typeComparer.constValue(callTypeArgs.head.tpe) match {
@@ -418,6 +414,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
418414
419415 val inlineCtx = inlineContext(call).fresh.setTyper(inlineTyper).setNewScope
420416
417+ def inlinedFromOutside (tree : Tree )(span : Span ): Tree =
418+ Inlined (EmptyTree , Nil , tree)(ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
419+
421420 // A tree type map to prepare the inlined body for typechecked.
422421 // The translation maps references to `this` and parameters to
423422 // 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) {
438437 tree.tpe match {
439438 case thistpe : ThisType =>
440439 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)
442443 case None => tree
443444 }
444445 case _ => tree
@@ -449,12 +450,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
449450 if (tree.name == nme.WILDCARD ) tree.span // From type match
450451 else if (tree.symbol.isTypeParam && tree.symbol.owner.isClass) tree.span // TODO is this the correct span?
451452 else paramSpan(tree.name)
453+ val inlinedCtx = ctx.withSource(inlinedMethod.topLevelClass.source)
452454 paramProxy.get(tree.tpe) match {
453455 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)
458458 case Some (t) if tree.isType =>
459459 TypeTree (t).withSpan(argSpan)
460460 case _ => tree
@@ -467,7 +467,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
467467
468468 // Apply inliner to `rhsToInline`, split off any implicit bindings from result, and
469469 // 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)
471471
472472 def issueError () = callValueArgss match {
473473 case (msgArg :: rest) :: Nil =>
@@ -1159,8 +1159,17 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
11591159 assert(level == 0 )
11601160 val inlinedFrom = enclosingInlineds.last
11611161 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+
11621171 if (ctx.reporter.hasErrors) EmptyTree
1163- else evaluatedSplice .withSpan(span)
1172+ else normalizedSplice .withSpan(span)
11641173 }
11651174
11661175}
0 commit comments