@@ -1405,27 +1405,29 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1405
1405
if (untpd.isFunctionWithUnknownParamType(arg)) {
1406
1406
def isUniform [T ](xs : List [T ])(p : (T , T ) => Boolean ) = xs.forall(p(_, xs.head))
1407
1407
val formalsForArg : List [Type ] = altFormals.map(_.head)
1408
- // For alternatives alt_1, ..., alt_n, test whether formal types for current argument are of the form
1409
- // (p_1_1, ..., p_m_1) => r_1
1410
- // ...
1411
- // (p_1_n, ..., p_m_n) => r_n
1412
- val decomposedFormalsForArg : List [Option [(List [Type ], Type , Boolean )]] =
1413
- formalsForArg.map(defn.FunctionOf .unapply)
1414
- if (decomposedFormalsForArg.forall(_.isDefined)) {
1415
- val formalParamTypessForArg : List [List [Type ]] =
1416
- decomposedFormalsForArg.map(_.get._1)
1417
- if (isUniform(formalParamTypessForArg)((x, y) => x.length == y.length)) {
1418
- val commonParamTypes = formalParamTypessForArg.transpose.map(ps =>
1419
- // Given definitions above, for i = 1,...,m,
1420
- // ps(i) = List(p_i_1, ..., p_i_n) -- i.e. a column
1421
- // If all p_i_k's are the same, assume the type as formal parameter
1422
- // type of the i'th parameter of the closure.
1423
- if (isUniform(ps)(ctx.typeComparer.isSameTypeWhenFrozen(_, _))) ps.head
1424
- else WildcardType )
1425
- val commonFormal = defn.FunctionOf (commonParamTypes, WildcardType )
1426
- overload.println(i " pretype arg $arg with expected type $commonFormal" )
1427
- pt.typedArg(arg, commonFormal)(ctx.addMode(Mode .ImplicitsEnabled ))
1408
+ def argTypesOfFormal (formal : Type ): List [Type ] =
1409
+ formal match {
1410
+ case defn.FunctionOf (args, result, isImplicit) => args
1411
+ case defn.PartialFunctionOf (arg, result) => arg :: Nil
1412
+ case _ => Nil
1428
1413
}
1414
+ val formalParamTypessForArg : List [List [Type ]] =
1415
+ formalsForArg.map(argTypesOfFormal)
1416
+ if (formalParamTypessForArg.forall(_.nonEmpty) &&
1417
+ isUniform(formalParamTypessForArg)((x, y) => x.length == y.length)) {
1418
+ val commonParamTypes = formalParamTypessForArg.transpose.map(ps =>
1419
+ // Given definitions above, for i = 1,...,m,
1420
+ // ps(i) = List(p_i_1, ..., p_i_n) -- i.e. a column
1421
+ // If all p_i_k's are the same, assume the type as formal parameter
1422
+ // type of the i'th parameter of the closure.
1423
+ if (isUniform(ps)(ctx.typeComparer.isSameTypeWhenFrozen(_, _))) ps.head
1424
+ else WildcardType )
1425
+ def isPartial = formalsForArg.forall(_.isRef(defn.PartialFunctionClass ))
1426
+ val commonFormal =
1427
+ if (isPartial) defn.PartialFunctionOf (commonParamTypes.head, newTypeVar(TypeBounds .empty))
1428
+ else defn.FunctionOf (commonParamTypes, WildcardType )
1429
+ overload.println(i " pretype arg $arg with expected type $commonFormal" )
1430
+ pt.typedArg(arg, commonFormal)(ctx.addMode(Mode .ImplicitsEnabled ))
1429
1431
}
1430
1432
}
1431
1433
recur(altFormals.map(_.tail), args1)
0 commit comments