@@ -321,27 +321,19 @@ object Splicer {
321321 protected def interpretNew (fn : Symbol , args : => List [Result ])(implicit env : Env ): Result
322322 protected def unexpectedTree (tree : Tree )(implicit env : Env ): Result
323323
324- private final def removeEraisedArguments (args : List [Tree ], fnTpe : Type ): List [Tree ] = {
325- var result = args
326- var index = 0
327- def loop (tp : Type ): Unit = tp match {
328- case tp : TermRef => loop(tp.underlying)
329- case tp : PolyType => loop(tp.resType)
330- case tp : MethodType if tp.isErasedMethod =>
331- tp.paramInfos.foreach { _ =>
332- result = result.updated(index, null )
333- index += 1
334- }
335- loop(tp.resType)
324+ private final def removeErasedArguments (args : List [List [Tree ]], fnTpe : Type ): List [List [Tree ]] =
325+ fnTpe match {
326+ case tp : TermRef => removeErasedArguments(args, tp.underlying)
327+ case tp : PolyType => removeErasedArguments(args, tp.resType)
328+ case tp : ExprType => removeErasedArguments(args, tp.resType)
336329 case tp : MethodType =>
337- index += tp.paramInfos.size
338- loop(tp.resType)
339- case _ => ()
330+ val tail = removeErasedArguments(args.tail, tp.resType)
331+ if (tp.isErasedMethod) tail else args.head :: tail
332+ case tp : AppliedType if defn.isImplicitFunctionType(tp) =>
333+ val tail = removeErasedArguments(args.tail, tp.args.last)
334+ if (defn.isErasedFunctionType(tp)) tail else args.head :: tail
335+ case tp => assert(args.isEmpty, tp); Nil
340336 }
341- loop(fnTpe)
342- assert(index == args.size)
343- result.filterNot(null .eq)
344- }
345337
346338 protected final def interpretTree (tree : Tree )(implicit env : Env ): Result = tree match {
347339 case Apply (TypeApply (fn, _), quoted :: Nil ) if fn.symbol == defn.InternalQuoted_exprQuote =>
@@ -368,16 +360,16 @@ object Splicer {
368360
369361 case Call (fn, args) =>
370362 if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package )) {
371- interpretNew(fn.symbol, args.map(interpretTree))
363+ interpretNew(fn.symbol, args.flatten. map(interpretTree))
372364 } else if (fn.symbol.is(Module )) {
373365 interpretModuleAccess(fn.symbol)
374366 } else if (fn.symbol.isStatic) {
375367 val module = fn.symbol.owner
376- def interpretedArgs = removeEraisedArguments (args, fn.tpe).map(arg => interpretTree(arg) )
368+ def interpretedArgs = removeErasedArguments (args, fn.tpe).flatten. map(interpretTree)
377369 interpretStaticMethodCall(module, fn.symbol, interpretedArgs)
378370 } else if (fn.qualifier.symbol.is(Module ) && fn.qualifier.symbol.isStatic) {
379371 val module = fn.qualifier.symbol.moduleClass
380- def interpretedArgs = removeEraisedArguments (args, fn.tpe).map(arg => interpretTree(arg) )
372+ def interpretedArgs = removeErasedArguments (args, fn.tpe).flatten. map(interpretTree)
381373 interpretStaticMethodCall(module, fn.symbol, interpretedArgs)
382374 } else if (env.contains(fn.name)) {
383375 env(fn.name)
@@ -418,15 +410,19 @@ object Splicer {
418410 }
419411
420412 object Call {
421- def unapply (arg : Tree ): Option [(RefTree , List [Tree ])] = arg match {
422- case Select (Call (fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
423- Some ((fn, args))
424- case fn : RefTree => Some ((fn, Nil ))
425- case Apply (Call (fn, args1), args2) => Some ((fn, args1 ::: args2)) // TODO improve performance
426- case TypeApply (Call (fn, args), _) => Some ((fn, args))
427- case _ => None
413+ def unapply (arg : Tree ): Option [(RefTree , List [List [Tree ]])] =
414+ Call0 .unapply(arg).map((fn, args) => (fn, args.reverse))
415+
416+ object Call0 {
417+ def unapply (arg : Tree ): Option [(RefTree , List [List [Tree ]])] = arg match {
418+ case Select (Call0 (fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
419+ Some ((fn, args))
420+ case fn : RefTree => Some ((fn, Nil ))
421+ case Apply (Call0 (fn, args1), args2) => Some ((fn, args2 :: args1))
422+ case TypeApply (Call0 (fn, args), _) => Some ((fn, args))
423+ case _ => None
424+ }
428425 }
429426 }
430427 }
431-
432428}
0 commit comments