@@ -1638,11 +1638,6 @@ trait Applications extends Compatibility {
1638
1638
val candidates = pt match {
1639
1639
case pt @ FunProto (args, resultType) =>
1640
1640
val numArgs = args.length
1641
- val normArgs = args.mapConserve {
1642
- case Block (Nil , expr) => expr
1643
- case x => x
1644
- }
1645
-
1646
1641
def sizeFits (alt : TermRef ): Boolean = alt.widen.stripPoly match {
1647
1642
case tp : MethodType =>
1648
1643
val ptypes = tp.paramInfos
@@ -1661,6 +1656,27 @@ trait Applications extends Compatibility {
1661
1656
alts.filter(sizeFits(_))
1662
1657
1663
1658
def narrowByShapes (alts : List [TermRef ]): List [TermRef ] =
1659
+
1660
+ /** Normalization steps before shape-checking arguments:
1661
+ *
1662
+ * { expr } --> expr
1663
+ * (x1, ..., xn) => expr --> ((x1, ..., xn)) => expr
1664
+ * if n > 1, no alternative takes `n` parameters,
1665
+ * and at least one alternative takes 1 parameter.
1666
+ */
1667
+ def normArg (arg : untpd.Tree ): untpd.Tree = arg match
1668
+ case Block (Nil , expr) => normArg(expr)
1669
+ case x @ untpd.Function (args, body) =>
1670
+ val numArgs = args.length
1671
+ def paramCount (ref : TermRef ) = ref.widen.firstParamTypes.length
1672
+ if numArgs > 1
1673
+ && ! alts.exists(paramCount(_) == numArgs)
1674
+ && alts.exists(paramCount(_) == 1 )
1675
+ then untpd.Function (untpd.Tuple (args) :: Nil , body)
1676
+ else arg
1677
+ case _ => arg
1678
+
1679
+ val normArgs = args.mapConserve(normArg)
1664
1680
if (normArgs exists untpd.isFunctionWithUnknownParamType)
1665
1681
if (hasNamedArg(args)) narrowByTrees(alts, args map treeShape, resultType)
1666
1682
else narrowByTypes(alts, normArgs map typeShape, resultType)
0 commit comments