@@ -250,7 +250,7 @@ object Splicer {
250
250
interpretModuleAccess(fn.symbol)
251
251
else if (fn.symbol.is(Method ) && fn.symbol.isStatic) {
252
252
val staticMethodCall = interpretedStaticMethodCall(fn.symbol.owner, fn.symbol)
253
- staticMethodCall(args.flatten.map(interpretTree ))
253
+ staticMethodCall(interpretArgs( args, fn.symbol.info ))
254
254
}
255
255
else if fn.symbol.isStatic then
256
256
assert(args.isEmpty)
@@ -260,7 +260,7 @@ object Splicer {
260
260
interpretModuleAccess(fn.qualifier.symbol)
261
261
else {
262
262
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
263
- staticMethodCall(args.flatten.map(interpretTree ))
263
+ staticMethodCall(interpretArgs( args, fn.symbol.info ))
264
264
}
265
265
else if (env.contains(fn.symbol))
266
266
env(fn.symbol)
@@ -289,6 +289,24 @@ object Splicer {
289
289
unexpectedTree(tree)
290
290
}
291
291
292
+ private def interpretArgs (argss : List [List [Tree ]], fnType : Type )(using Env ): List [Object ] = {
293
+ fnType match
294
+ case fnType : PolyType => interpretArgs(argss, fnType.resType)
295
+ case fnType : MethodType if fnType.isErasedMethod => interpretArgs(argss, fnType.resType)
296
+ case fnType : MethodType =>
297
+ val interprededHeadParams =
298
+ for (info, arg) <- fnType.paramInfos.lazyZip(argss.head) yield
299
+ info match
300
+ case _ : ExprType => () => interpretTree(arg) // by-name argument
301
+ case _ => interpretTree(arg) // by-value argument
302
+ interprededHeadParams.toList ::: interpretArgs(argss.tail, fnType.resType)
303
+ case _ =>
304
+ // If the final result type is a context function the rest of the args are interpreted as by-value.
305
+ // for `def f(x: Int): Int ?=> Int` we call directly the verison that does not create the closure
306
+ // `def f$direct(x: Int)(x$1: Int): Int`.
307
+ argss.flatMap(_.map(interpretTree))
308
+ }
309
+
292
310
private def interpretBlock (stats : List [Tree ], expr : Tree )(implicit env : Env ) = {
293
311
var unexpected : Option [Object ] = None
294
312
val newEnv = stats.foldLeft(env)((accEnv, stat) => stat match {
0 commit comments