@@ -15,9 +15,9 @@ package tools.nsc
15
15
package transform
16
16
17
17
import scala .annotation .tailrec
18
-
19
18
import symtab .Flags ._
20
19
import scala .collection .mutable
20
+ import scala .collection .mutable .ListBuffer
21
21
import scala .reflect .internal .util .ListOfNil
22
22
23
23
/* <export> */
@@ -247,14 +247,15 @@ abstract class UnCurry extends InfoTransform
247
247
}
248
248
}
249
249
250
- def transformArgs (pos : Position , fun : Symbol , args : List [Tree ], formals : List [Type ]): List [Tree ] = {
250
+ def transformArgs (pos : Position , fun : Symbol , args : List [Tree ], params : List [Symbol ]): List [Tree ] = {
251
251
val isJava = fun.isJavaDefined
252
- def transformVarargs (varargsElemType : Type ) = {
252
+
253
+ def transformVarargs (varargsElemType : Type ): List [Tree ] = {
253
254
def mkArrayValue (ts : List [Tree ], elemtp : Type ) =
254
255
ArrayValue (TypeTree (elemtp), ts) setType arrayType(elemtp)
255
256
256
257
// when calling into scala varargs, make sure it's a sequence.
257
- def arrayToSequence (tree : Tree , elemtp : Type , copy : Boolean ) = {
258
+ def arrayToSequence (tree : Tree , elemtp : Type , copy : Boolean ): Tree = {
258
259
exitingUncurry {
259
260
localTyper.typedPos(pos) {
260
261
val pt = arrayType(elemtp)
@@ -273,7 +274,7 @@ abstract class UnCurry extends InfoTransform
273
274
}
274
275
275
276
// when calling into java varargs, make sure it's an array - see bug #1360
276
- def sequenceToArray (tree : Tree ) = {
277
+ def sequenceToArray (tree : Tree ): Tree = {
277
278
val toArraySym = tree.tpe member nme.toArray
278
279
assert(toArraySym != NoSymbol )
279
280
def getClassTag (tp : Type ): Tree = {
@@ -314,7 +315,7 @@ abstract class UnCurry extends InfoTransform
314
315
else arrayToSequence(tree, varargsElemType, copy = isNewCollections) // existing array, make a defensive copy
315
316
}
316
317
else {
317
- def mkArray = mkArrayValue(args drop (formals .length - 1 ), varargsElemType)
318
+ def mkArray = mkArrayValue(args drop (params .length - 1 ), varargsElemType)
318
319
if (javaStyleVarArgs) mkArray
319
320
else if (args.isEmpty) gen.mkNil // avoid needlessly double-wrapping an empty argument list
320
321
else arrayToSequence(mkArray, varargsElemType, copy = false ) // fresh array, no need to copy
@@ -328,18 +329,22 @@ abstract class UnCurry extends InfoTransform
328
329
}
329
330
}
330
331
}
331
- args.take(formals.length - 1 ) :+ (suffix setType formals.last)
332
+ val args1 = ListBuffer [Tree ]()
333
+ args1 ++= args.iterator.take(params.length - 1 )
334
+ args1 += suffix setType params.last.info
335
+ args1.toList
332
336
}
333
337
334
- val args1 = if (isVarArgTypes(formals)) transformVarargs(formals.last.typeArgs.head.widen) else args
338
+ val isVarargs = isVarArgsList(params)
339
+ val args1 = if (isVarargs) transformVarargs(params.last.info.typeArgs.head.widen) else args
335
340
336
- map2(formals, args1 ) { (formal, arg ) =>
337
- if (! isByNameParamType(formal )) arg
341
+ map2Conserve(args1, params ) { (arg, param ) =>
342
+ if (! isByNameParamType(param.info )) arg
338
343
else if (isByNameRef(arg)) { // thunk does not need to be forced because it's a reference to a by-name arg passed to a by-name param
339
344
byNameArgs += arg
340
345
arg setType functionType(Nil , arg.tpe)
341
346
} else {
342
- log(s " Argument ' $arg' at line ${arg.pos.line} is $formal from ${fun.fullName}" )
347
+ log(s " Argument ' $arg' at line ${arg.pos.line} is ${param.info} from ${fun.fullName}" )
343
348
def canUseDirectly (qual : Tree ) = qual.tpe.typeSymbol.isSubClass(FunctionClass (0 )) && treeInfo.isExprSafeToInline(qual)
344
349
arg match {
345
350
// don't add a thunk for by-name argument if argument already is an application of
@@ -482,16 +487,16 @@ abstract class UnCurry extends InfoTransform
482
487
super .transform(tree)
483
488
484
489
case Apply (fn, args) =>
485
- // Read formals before `transform(fn)`, because UnCurry replaces T* by Seq[T] (see DesugaredParameterType).
490
+ // Read the param symbols before `transform(fn)`, because UnCurry replaces T* by Seq[T] (see DesugaredParameterType).
486
491
// The call to `transformArgs` below needs `formals` that still have varargs.
487
- val formals = fn.tpe.paramTypes
492
+ val fnParams = fn.tpe.params
488
493
val transformedFn = transform(fn)
489
494
// scala/bug#6479: no need to lift in args to label jumps
490
495
// scala/bug#11127: boolean && / || are emitted using jumps, the lhs stack value is consumed by the conditional jump
491
496
val noReceiverOnStack = fn.symbol.isLabel || fn.symbol == currentRun.runDefinitions.Boolean_and || fn.symbol == currentRun.runDefinitions.Boolean_or
492
497
val needLift = needTryLift || ! noReceiverOnStack
493
498
withNeedLift(needLift) {
494
- treeCopy.Apply (tree, transformedFn, transformTrees(transformArgs(tree.pos, fn.symbol, args, formals )))
499
+ treeCopy.Apply (tree, transformedFn, transformTrees(transformArgs(tree.pos, fn.symbol, args, fnParams )))
495
500
}
496
501
497
502
case Assign (_ : RefTree , _) =>
0 commit comments