@@ -193,6 +193,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
193193 */
194194 protected def liftFun (): Unit = ()
195195
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+
196202 /** A flag signalling that the typechecking the application was so far successful */
197203 private [this ] var _ok = true
198204
@@ -205,12 +211,25 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
205211 /** The function's type after widening and instantiating polytypes
206212 * with TypeParamRefs in constraint set
207213 */
208- val methType = funType .widen match {
214+ lazy val methType : Type = liftedFunType .widen match {
209215 case funType : MethodType => funType
210216 case funType : PolyType => constrained(funType).resultType
211217 case tp => tp // was: funType
212218 }
213219
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+
214233 /** The arguments re-ordered so that each named argument matches the
215234 * same-named formal parameter.
216235 */
@@ -231,6 +250,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
231250 ()
232251 else
233252 fail(err.typeMismatchMsg(methType.resultType, resultType))
253+
234254 // match all arguments with corresponding formal parameters
235255 matchArgs(orderedArgs, methType.paramInfos, 0 )
236256 case _ =>
@@ -425,8 +445,6 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
425445 }
426446
427447 def tryDefault (n : Int , args1 : List [Arg ]): Unit = {
428- if (! isJavaAnnotConstr(methRef.symbol))
429- liftFun()
430448 val getter = findDefaultGetter(n + numArgs(normalizedFun))
431449 if (getter.isEmpty) missingArg(n)
432450 else {
0 commit comments