@@ -10,7 +10,8 @@ import dotty.tools.dotc.core.Contexts._
10
10
import dotty .tools .dotc .core .Decorators ._
11
11
import dotty .tools .dotc .core .Flags ._
12
12
import dotty .tools .dotc .core .NameKinds .FlatName
13
- import dotty .tools .dotc .core .Names .Name
13
+ import dotty .tools .dotc .core .Names .{Name , TermName }
14
+ import dotty .tools .dotc .core .StdNames .nme
14
15
import dotty .tools .dotc .core .StdNames .str .MODULE_INSTANCE_FIELD
15
16
import dotty .tools .dotc .core .quoted ._
16
17
import dotty .tools .dotc .core .Types ._
@@ -113,19 +114,22 @@ object Splicer {
113
114
114
115
protected def interpretStaticMethodCall (fn : Symbol , args : => List [Object ])(implicit env : Env ): Object = {
115
116
val instance = loadModule(fn.owner)
116
- val name =
117
- if (! defn.isImplicitFunctionType(fn.info.finalResultType)) fn.name
118
- else NameKinds .DirectMethodName (fn.name.asTermName) // Call implicit function type direct method
117
+ def getDirectName (tp : Type , name : TermName ): TermName = tp.widenDealias match {
118
+ case tp : AppliedType if defn.isImplicitFunctionType(tp) =>
119
+ getDirectName(tp.args.last, NameKinds .DirectMethodName (name))
120
+ case _ => name
121
+ }
122
+ val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
119
123
val method = getMethod(instance.getClass, name, paramsSig(fn))
120
124
stopIfRuntimeException(method.invoke(instance, args : _* ))
121
125
}
122
126
123
- protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Object =
124
- loadModule(fn.symbol. moduleClass)
127
+ protected def interpretModuleAccess (fn : Symbol )(implicit env : Env ): Object =
128
+ loadModule(fn.moduleClass)
125
129
126
- protected def interpretNew (fn : RefTree , args : => List [Result ])(implicit env : Env ): Object = {
127
- val clazz = loadClass(fn.symbol. owner.fullName)
128
- val constr = clazz.getConstructor(paramsSig(fn.symbol ): _* )
130
+ protected def interpretNew (fn : Symbol , args : => List [Result ])(implicit env : Env ): Object = {
131
+ val clazz = loadClass(fn.owner.fullName)
132
+ val constr = clazz.getConstructor(paramsSig(fn): _* )
129
133
constr.newInstance(args : _* ).asInstanceOf [Object ]
130
134
}
131
135
@@ -234,14 +238,15 @@ object Splicer {
234
238
else if (sym == defn.DoubleClass ) classOf [Double ]
235
239
else java.lang.Class .forName(javaSig(param), false , classLoader)
236
240
}
237
- val extraParams = sym.info.finalResultType .widenDealias match {
241
+ def getExtraParams ( tp : Type ) : List [ Type ] = tp .widenDealias match {
238
242
case tp : AppliedType if defn.isImplicitFunctionType(tp) =>
239
243
// Call implicit function type direct method
240
- tp.args.init.map(arg => TypeErasure .erasure(arg))
244
+ tp.args.init.map(arg => TypeErasure .erasure(arg)) ::: getExtraParams(tp.args.last)
241
245
case _ => Nil
242
246
}
247
+ val extraParams = getExtraParams(sym.info.finalResultType)
243
248
val allParams = TypeErasure .erasure(sym.info) match {
244
- case meth : MethodType => ( meth.paramInfos ::: extraParams)
249
+ case meth : MethodType => meth.paramInfos ::: extraParams
245
250
case _ => extraParams
246
251
}
247
252
allParams.map(paramClass)
@@ -266,8 +271,8 @@ object Splicer {
266
271
protected def interpretTastyContext ()(implicit env : Env ): Boolean = true
267
272
protected def interpretQuoteContext ()(implicit env : Env ): Boolean = true
268
273
protected def interpretStaticMethodCall (fn : Symbol , args : => List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
269
- protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Boolean = true
270
- protected def interpretNew (fn : RefTree , args : => List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
274
+ protected def interpretModuleAccess (fn : Symbol )(implicit env : Env ): Boolean = true
275
+ protected def interpretNew (fn : Symbol , args : => List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
271
276
272
277
def unexpectedTree (tree : tpd.Tree )(implicit env : Env ): Boolean = {
273
278
// Assuming that top-level splices can only be in inline methods
@@ -288,8 +293,8 @@ object Splicer {
288
293
protected def interpretVarargs (args : List [Result ])(implicit env : Env ): Result
289
294
protected def interpretTastyContext ()(implicit env : Env ): Result
290
295
protected def interpretStaticMethodCall (fn : Symbol , args : => List [Result ])(implicit env : Env ): Result
291
- protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Result
292
- protected def interpretNew (fn : RefTree , args : => List [Result ])(implicit env : Env ): Result
296
+ protected def interpretModuleAccess (fn : Symbol )(implicit env : Env ): Result
297
+ protected def interpretNew (fn : Symbol , args : => List [Result ])(implicit env : Env ): Result
293
298
protected def unexpectedTree (tree : Tree )(implicit env : Env ): Result
294
299
295
300
protected final def interpretTree (tree : Tree )(implicit env : Env ): Result = tree match {
@@ -307,19 +312,14 @@ object Splicer {
307
312
308
313
case Call (fn, args) =>
309
314
if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package )) {
310
- interpretNew(fn, args.map(interpretTree))
315
+ interpretNew(fn.symbol , args.map(interpretTree))
311
316
} else if (fn.symbol.isStatic) {
312
- if (fn.symbol.is(Module )) interpretModuleAccess(fn)
317
+ if (fn.symbol.is(Module )) interpretModuleAccess(fn.symbol )
313
318
else interpretStaticMethodCall(fn.symbol, args.map(arg => interpretTree(arg)))
314
319
} else if (env.contains(fn.name)) {
315
320
env(fn.name)
316
321
} else {
317
- fn match {
318
- case fn @ Select (Call (fn0, args0), _) if fn0.symbol.isStatic && fn.symbol.info.isImplicitMethod =>
319
- // Call implicit function type direct method
320
- interpretStaticMethodCall(fn0.symbol, (args0 ::: args).map(arg => interpretTree(arg)))
321
- case _ => unexpectedTree(tree)
322
- }
322
+ unexpectedTree(tree)
323
323
}
324
324
325
325
// Interpret `foo(j = x, i = y)` which it is expanded to
@@ -347,6 +347,7 @@ object Splicer {
347
347
348
348
object Call {
349
349
def unapply (arg : Tree ): Option [(RefTree , List [Tree ])] = arg match {
350
+ case Select (Call (fn, args), nme.apply) => Some ((fn, args))
350
351
case fn : RefTree => Some ((fn, Nil ))
351
352
case Apply (Call (fn, args1), args2) => Some ((fn, args1 ::: args2)) // TODO improve performance
352
353
case TypeApply (Call (fn, args), _) => Some ((fn, args))
0 commit comments