@@ -1656,27 +1656,39 @@ trait Applications extends Compatibility {
16561656 alts.filter(sizeFits(_))
16571657
16581658 def narrowByShapes (alts : List [TermRef ]): List [TermRef ] =
1659-
1659+
16601660 /** Normalization steps before shape-checking arguments:
16611661 *
16621662 * { expr } --> expr
16631663 * (x1, ..., xn) => expr --> ((x1, ..., xn)) => expr
1664- * if n > 1, no alternative takes `n` parameters,
1665- * and at least one alternative takes 1 parameter.
1664+ * if n > 1, no alternative has a corresponding formal parameter that
1665+ * is an n-ary function, and at least one alternative has a corresponding
1666+ * formal parameter that is a unary function.
16661667 */
1667- def normArg (arg : untpd.Tree ): untpd.Tree = arg match
1668- case Block (Nil , expr) => normArg(expr)
1669- case x @ untpd.Function (args, body) =>
1668+ def normArg (arg : untpd.Tree , idx : Int ): untpd.Tree = arg match
1669+ case Block (Nil , expr) => normArg(expr, idx)
1670+ case untpd.Function (args, body) =>
1671+
1672+ // If ref refers to a method whose parameter at index `idx` is a function type,
1673+ // the arity of that function, otherise 0.
1674+ def paramCount (ref : TermRef ) =
1675+ val formals = ref.widen.firstParamTypes
1676+ if formals.length > idx then
1677+ formals(idx) match
1678+ case defn.FunctionOf (args, _, _, _) => args.length
1679+ case _ => 0
1680+ else 0
1681+
16701682 val numArgs = args.length
1671- def paramCount (ref : TermRef ) = ref.widen.firstParamTypes.length
16721683 if numArgs > 1
16731684 && ! alts.exists(paramCount(_) == numArgs)
16741685 && alts.exists(paramCount(_) == 1 )
16751686 then untpd.Function (untpd.Tuple (args) :: Nil , body)
16761687 else arg
16771688 case _ => arg
1678-
1679- val normArgs = args.mapConserve(normArg)
1689+ end normArg
1690+
1691+ val normArgs = args.mapWithIndexConserve(normArg)
16801692 if (normArgs exists untpd.isFunctionWithUnknownParamType)
16811693 if (hasNamedArg(args)) narrowByTrees(alts, args map treeShape, resultType)
16821694 else narrowByTypes(alts, normArgs map typeShape, resultType)
0 commit comments