Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cc281e

Browse files
committed
Notice args of forwarder when generating it
1 parent 5381be8 commit 9cc281e

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,16 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
327327
enclosingStaticModules.foldLeft(tree)((tree, moduleClass) => tree.substituteThis(moduleClass, gen.mkAttributedIdent(moduleClass.sourceModule)) )
328328
}
329329

330-
newDefDef(methSym, substThisForModule(moveToMethod(useMethodParams(fun.body))))(tpt = TypeTree(resTp))
330+
val body = useMethodParams(fun.body)
331+
if (methParamSyms.exists(p => isByNameParamType(p.info))) {
332+
val bynames = methParamSyms.zip(fun.vparams).collect { case (mp, vp) if isByNameParamType(mp.info) != isByNameParamType(vp.tpt.tpe) => mp }
333+
if (bynames.nonEmpty)
334+
body.foreach {
335+
case t @ Ident(_) if bynames.contains(t.symbol) => t.updateAttachment(PreserveArg)
336+
case _ =>
337+
}
338+
}
339+
newDefDef(methSym, substThisForModule(moveToMethod(body)))(tpt = TypeTree(resTp))
331340
}
332341

333342
/**

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,6 @@ abstract class UnCurry extends InfoTransform
246246
else typeNewFun match {
247247
case typedNewFun @ Block(stats, expr: Function) =>
248248
val expansion = gen.expandFunction(localTyper)(expr, inConstructorFlag)
249-
expansion match {
250-
case Block(ClassDef(_, _, _, Template(_, _, body)) :: Nil, _) =>
251-
body.last match {
252-
case DefDef(_, _, _, _, _, Apply(_, args)) => noApply.addAll(args) // samDef args are pass-thru
253-
case _ =>
254-
}
255-
case _ =>
256-
}
257249
treeCopy.Block(typedNewFun, stats, expansion)
258250
case x => throw new MatchError(x)
259251
}
@@ -467,7 +459,7 @@ abstract class UnCurry extends InfoTransform
467459
else translateSynchronized(tree) match {
468460
case dd @ DefDef(mods, name, tparams, _, tpt, rhs) =>
469461
// Remove default argument trees from parameter ValDefs, scala/bug#4812
470-
val vparamssNoRhs = dd.vparamss mapConserve (_ mapConserve {p =>
462+
val vparamssNoRhs = dd.vparamss.mapConserve(_.mapConserve { p =>
471463
treeCopy.ValDef(p, p.mods, p.name, p.tpt, EmptyTree)
472464
})
473465

@@ -558,7 +550,7 @@ abstract class UnCurry extends InfoTransform
558550
if (isByNameRef(tree1)) {
559551
val tree2 = tree1 setType functionType(Nil, tree1.tpe)
560552
return {
561-
if (noApply contains tree2) tree2
553+
if (tree.attachments.contains[PreserveArg.type] || noApply.contains(tree2)) tree2
562554
else localTyper.typedPos(tree1.pos)(Apply(Select(tree2, nme.apply), Nil))
563555
}
564556
}

src/reflect/scala/reflect/internal/StdAttachments.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,7 @@ trait StdAttachments {
186186

187187
/** This Bind tree was derived immediately from the given tree, for unused accounting. */
188188
case class VarAlias(tree: Tree /*Bind | ValDef*/) extends PlainAttachment
189+
190+
/** Do not mangle the arg. It is passed directly in a forwarding application. */
191+
case object PreserveArg extends PlainAttachment
189192
}

src/reflect/scala/reflect/runtime/JavaUniverseForce.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
9292
this.DiscardedExpr
9393
this.BooleanParameterType
9494
this.VarAlias
95+
this.PreserveArg
9596
this.noPrint
9697
this.typeDebug
9798
// inaccessible: this.posAssigner

test/files/run/t11237.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//> abusing options -Vprint:~uncurry
1+
// using options -Vprint:~uncurry
2+
23
trait Semigroup[F] { self =>
34
def append(f1: F, f2: => F): F
45
val z = 10

0 commit comments

Comments
 (0)