@@ -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,25 @@ 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 = liftedFunType .widen match {
209
215
case funType : MethodType => funType
210
216
case funType : PolyType => constrained(funType).resultType
211
217
case tp => tp // was: funType
212
218
}
213
219
220
+ def reqiredArgNum (tp : Type ): Int = tp.widen match {
221
+ case funType : MethodType => funType.paramInfos.size
222
+ case funType : PolyType => reqiredArgNum(funType.resultType)
223
+ case tp => args.size
224
+ }
225
+
226
+ lazy val liftedFunType =
227
+ if (needLiftFun) {
228
+ liftFun()
229
+ normalizedFun.tpe
230
+ }
231
+ else funType
232
+
214
233
/** The arguments re-ordered so that each named argument matches the
215
234
* same-named formal parameter.
216
235
*/
@@ -231,6 +250,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
231
250
()
232
251
else
233
252
fail(err.typeMismatchMsg(methType.resultType, resultType))
253
+
234
254
// match all arguments with corresponding formal parameters
235
255
matchArgs(orderedArgs, methType.paramInfos, 0 )
236
256
case _ =>
@@ -425,8 +445,6 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
425
445
}
426
446
427
447
def tryDefault (n : Int , args1 : List [Arg ]): Unit = {
428
- if (! isJavaAnnotConstr(methRef.symbol))
429
- liftFun()
430
448
val getter = findDefaultGetter(n + numArgs(normalizedFun))
431
449
if (getter.isEmpty) missingArg(n)
432
450
else {
0 commit comments