@@ -193,6 +193,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
193
193
*/
194
194
protected def liftFun (): Unit = ()
195
195
196
+ /** Whether `liftFun` is needed? It is the case if default arguments are used.
197
+ */
198
+ protected def needLiftFun : Boolean =
199
+ ! isJavaAnnotConstr(methRef.symbol) &&
200
+ args.size < reqiredArgNum(funType)
201
+
196
202
/** A flag signalling that the typechecking the application was so far successful */
197
203
private [this ] var _ok = true
198
204
@@ -205,12 +211,27 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
205
211
/** The function's type after widening and instantiating polytypes
206
212
* with TypeParamRefs in constraint set
207
213
*/
208
- val methType = funType.widen match {
214
+ lazy val methType : Type = constrainType(liftedFunType)
215
+
216
+ def constrainType (tp : Type ) = tp.widen match {
209
217
case funType : MethodType => funType
210
218
case funType : PolyType => constrained(funType).resultType
211
219
case tp => tp // was: funType
212
220
}
213
221
222
+ def reqiredArgNum (tp : Type ): Int = tp.widen match {
223
+ case funType : MethodType => funType.paramInfos.size
224
+ case funType : PolyType => reqiredArgNum(funType.resultType)
225
+ case tp => args.size
226
+ }
227
+
228
+ def liftedFunType =
229
+ if (needLiftFun) {
230
+ liftFun()
231
+ constrainType(normalizedFun.tpe)
232
+ }
233
+ else funType
234
+
214
235
/** The arguments re-ordered so that each named argument matches the
215
236
* same-named formal parameter.
216
237
*/
@@ -220,7 +241,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
220
241
else
221
242
args
222
243
223
- protected def init () = methType match {
244
+ protected def init () = methType.widen match {
224
245
case methType : MethodType =>
225
246
// apply the result type constraint, unless method type is dependent
226
247
val resultApprox = resultTypeApprox(methType)
@@ -231,6 +252,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
231
252
()
232
253
else
233
254
fail(err.typeMismatchMsg(methType.resultType, resultType))
255
+
234
256
// match all arguments with corresponding formal parameters
235
257
matchArgs(orderedArgs, methType.paramInfos, 0 )
236
258
case _ =>
@@ -425,8 +447,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
425
447
}
426
448
427
449
def tryDefault (n : Int , args1 : List [Arg ]): Unit = {
428
- if (! isJavaAnnotConstr(methRef.symbol))
429
- liftFun()
450
+ // if (!isJavaAnnotConstr(methRef.symbol))
451
+ // liftFun()
430
452
val getter = findDefaultGetter(n + numArgs(normalizedFun))
431
453
if (getter.isEmpty) missingArg(n)
432
454
else {
@@ -543,7 +565,6 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
543
565
private [this ] var typedArgBuf = new mutable.ListBuffer [Tree ]
544
566
private [this ] var liftedDefs : mutable.ListBuffer [Tree ] = null
545
567
private [this ] var myNormalizedFun : Tree = fun
546
- init()
547
568
548
569
def addArg (arg : Tree , formal : Type ): Unit =
549
570
typedArgBuf += adapt(arg, formal.widenExpr)
@@ -598,6 +619,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
598
619
private def sameSeq [T <: Trees .Tree [_]](xs : List [T ], ys : List [T ]): Boolean = firstDiff(xs, ys) < 0
599
620
600
621
val result = {
622
+ init()
623
+
601
624
var typedArgs = typedArgBuf.toList
602
625
def app0 = cpy.Apply (app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
603
626
val app1 =
@@ -606,7 +629,6 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
606
629
if (! sameSeq(args, orderedArgs.dropWhile(_ eq EmptyTree )) && ! isJavaAnnotConstr(methRef.symbol)) {
607
630
// need to lift arguments to maintain evaluation order in the
608
631
// presence of argument reorderings.
609
-
610
632
liftFun()
611
633
612
634
// lift arguments in the definition order
0 commit comments