@@ -318,6 +318,20 @@ object Splicer {
318
318
protected def interpretNew (fn : Symbol , args : => List [Result ])(implicit env : Env ): Result
319
319
protected def unexpectedTree (tree : Tree )(implicit env : Env ): Result
320
320
321
+ private final def removeErasedArguments (args : List [List [Tree ]], fnTpe : Type ): List [List [Tree ]] =
322
+ fnTpe match {
323
+ case tp : TermRef => removeErasedArguments(args, tp.underlying)
324
+ case tp : PolyType => removeErasedArguments(args, tp.resType)
325
+ case tp : ExprType => removeErasedArguments(args, tp.resType)
326
+ case tp : MethodType =>
327
+ val tail = removeErasedArguments(args.tail, tp.resType)
328
+ if (tp.isErasedMethod) tail else args.head :: tail
329
+ case tp : AppliedType if defn.isImplicitFunctionType(tp) =>
330
+ val tail = removeErasedArguments(args.tail, tp.args.last)
331
+ if (defn.isErasedFunctionType(tp)) tail else args.head :: tail
332
+ case tp => assert(args.isEmpty, tp); Nil
333
+ }
334
+
321
335
protected final def interpretTree (tree : Tree )(implicit env : Env ): Result = tree match {
322
336
case Apply (TypeApply (fn, _), quoted :: Nil ) if fn.symbol == defn.InternalQuoted_exprQuote =>
323
337
val quoted1 = quoted match {
@@ -340,15 +354,17 @@ object Splicer {
340
354
341
355
case Call (fn, args) =>
342
356
if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package )) {
343
- interpretNew(fn.symbol, args.map(interpretTree))
357
+ interpretNew(fn.symbol, args.flatten. map(interpretTree))
344
358
} else if (fn.symbol.is(Module )) {
345
359
interpretModuleAccess(fn.symbol)
346
360
} else if (fn.symbol.isStatic) {
347
361
val module = fn.symbol.owner
348
- interpretStaticMethodCall(module, fn.symbol, args.map(arg => interpretTree(arg)))
362
+ def interpretedArgs = removeErasedArguments(args, fn.tpe).flatten.map(interpretTree)
363
+ interpretStaticMethodCall(module, fn.symbol, interpretedArgs)
349
364
} else if (fn.qualifier.symbol.is(Module ) && fn.qualifier.symbol.isStatic) {
350
365
val module = fn.qualifier.symbol.moduleClass
351
- interpretStaticMethodCall(module, fn.symbol, args.map(arg => interpretTree(arg)))
366
+ def interpretedArgs = removeErasedArguments(args, fn.tpe).flatten.map(interpretTree)
367
+ interpretStaticMethodCall(module, fn.symbol, interpretedArgs)
352
368
} else if (env.contains(fn.name)) {
353
369
env(fn.name)
354
370
} else if (tree.symbol.is(InlineProxy )) {
@@ -388,15 +404,19 @@ object Splicer {
388
404
}
389
405
390
406
object Call {
391
- def unapply (arg : Tree ): Option [(RefTree , List [Tree ])] = arg match {
392
- case Select (Call (fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
393
- Some ((fn, args))
394
- case fn : RefTree => Some ((fn, Nil ))
395
- case Apply (Call (fn, args1), args2) => Some ((fn, args1 ::: args2)) // TODO improve performance
396
- case TypeApply (Call (fn, args), _) => Some ((fn, args))
397
- case _ => None
407
+ def unapply (arg : Tree ): Option [(RefTree , List [List [Tree ]])] =
408
+ Call0 .unapply(arg).map((fn, args) => (fn, args.reverse))
409
+
410
+ object Call0 {
411
+ def unapply (arg : Tree ): Option [(RefTree , List [List [Tree ]])] = arg match {
412
+ case Select (Call0 (fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
413
+ Some ((fn, args))
414
+ case fn : RefTree => Some ((fn, Nil ))
415
+ case Apply (Call0 (fn, args1), args2) => Some ((fn, args2 :: args1))
416
+ case TypeApply (Call0 (fn, args), _) => Some ((fn, args))
417
+ case _ => None
418
+ }
398
419
}
399
420
}
400
421
}
401
-
402
422
}
0 commit comments