@@ -2214,19 +2214,26 @@ trait Applications extends Compatibility {
22142214 case untpd.Function (args : List [untpd.ValDef ] @ unchecked, body) =>
22152215
22162216 // If ref refers to a method whose parameter at index `idx` is a function type,
2217- // the arity of that function, otherise -1.
2218- def paramCount (ref : TermRef ) =
2217+ // the parameters of that function, otherwise Nil.
2218+ // We return Nil for both nilary functions and non-functions,
2219+ // because we won't be making tupled functions for nilary functions anyways,
2220+ // seeing as there is no Tuple0.
2221+ def params (ref : TermRef ) =
22192222 val formals = ref.widen.firstParamTypes
22202223 if formals.length > idx then
22212224 formals(idx).dealias match
2222- case defn.FunctionNOf (args, _, _) => args.length
2223- case _ => - 1
2224- else - 1
2225+ case defn.FunctionNOf (args, _, _) => args
2226+ case _ => Nil
2227+ else Nil
2228+
2229+ def isCorrectUnaryFunction (alt : TermRef ): Boolean =
2230+ val formals = params(alt)
2231+ formals.length == 1 && ptIsCorrectProduct(formals.head, args)
22252232
22262233 val numArgs = args.length
2227- if numArgs != 1
2228- && ! alts.exists(paramCount (_) == numArgs)
2229- && alts.exists(paramCount(_) == 1 )
2234+ if numArgs > 1
2235+ && ! alts.exists(params (_).lengthIs == numArgs)
2236+ && alts.exists(isCorrectUnaryFunction )
22302237 then
22312238 desugar.makeTupledFunction(args, body, isGenericTuple = true )
22322239 // `isGenericTuple = true` is the safe choice here. It means the i'th tuple
@@ -2395,6 +2402,13 @@ trait Applications extends Compatibility {
23952402 }
23962403 end resolveOverloaded1
23972404
2405+ /** Is `formal` a product type which is elementwise compatible with `params`? */
2406+ def ptIsCorrectProduct (formal : Type , params : List [untpd.ValDef ])(using Context ): Boolean =
2407+ isFullyDefined(formal, ForceDegree .flipBottom)
2408+ && defn.isProductSubType(formal)
2409+ && tupleComponentTypes(formal).corresponds(params): (argType, param) =>
2410+ param.tpt.isEmpty || argType.widenExpr <:< typedAheadType(param.tpt).tpe
2411+
23982412 /** The largest suffix of `paramss` that has the same first parameter name as `t`,
23992413 * plus the number of term parameters in `paramss` that come before that suffix.
24002414 */
0 commit comments