@@ -2935,14 +2935,31 @@ class Typer extends Namer
29352935 false
29362936 }
29372937
2938+ /** Should we tuple or untuple the argument before application?
2939+ * If auto-tupling is enabled then
2940+ *
2941+ * - we tuple n-ary arguments where n > 0 if the function consists
2942+ * only of unary alternatives
2943+ * - we untuple tuple arguments of infix operations if the function
2944+ * does not consist only of unary alternatives.
2945+ */
2946+ def needsTupledDual (funType : Type , pt : FunProto ): Boolean =
2947+ pt.args match
2948+ case untpd.Tuple (elems) :: Nil =>
2949+ elems.length > 1
2950+ && pt.applyKind == ApplyKind .InfixTuple
2951+ && ! isUnary(funType)
2952+ case args =>
2953+ args.lengthCompare(1 ) > 0
2954+ && isUnary(funType)
2955+ && autoTuplingEnabled
2956+
29382957 def adaptToArgs (wtp : Type , pt : FunProto ): Tree = wtp match {
29392958 case wtp : MethodOrPoly =>
29402959 def methodStr = methPart(tree).symbol.showLocated
29412960 if (matchingApply(wtp, pt))
2942- if (pt.args.lengthCompare(1 ) > 0 && isUnary(wtp) && autoTuplingEnabled)
2943- adapt(tree, pt.tupled, locked)
2944- else
2945- tree
2961+ if needsTupledDual(wtp, pt) then adapt(tree, pt.tupledDual, locked)
2962+ else tree
29462963 else if (wtp.isContextualMethod)
29472964 def isContextBoundParams = wtp.stripPoly match
29482965 case MethodType (EvidenceParamName (_) :: _) => true
@@ -3472,8 +3489,8 @@ class Typer extends Namer
34723489 case ref : TermRef =>
34733490 pt match {
34743491 case pt : FunProto
3475- if pt.args.lengthCompare( 1 ) > 0 && isUnary( ref) && autoTuplingEnabled =>
3476- adapt(tree, pt.tupled , locked)
3492+ if needsTupledDual( ref, pt ) && autoTuplingEnabled =>
3493+ adapt(tree, pt.tupledDual , locked)
34773494 case _ =>
34783495 adaptOverloaded(ref)
34793496 }
0 commit comments