@@ -2214,19 +2214,26 @@ trait Applications extends Compatibility {
2214
2214
case untpd.Function (args : List [untpd.ValDef ] @ unchecked, body) =>
2215
2215
2216
2216
// 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 ) =
2219
2222
val formals = ref.widen.firstParamTypes
2220
2223
if formals.length > idx then
2221
2224
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)
2225
2232
2226
2233
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 )
2230
2237
then
2231
2238
desugar.makeTupledFunction(args, body, isGenericTuple = true )
2232
2239
// `isGenericTuple = true` is the safe choice here. It means the i'th tuple
@@ -2395,6 +2402,13 @@ trait Applications extends Compatibility {
2395
2402
}
2396
2403
end resolveOverloaded1
2397
2404
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
+
2398
2412
/** The largest suffix of `paramss` that has the same first parameter name as `t`,
2399
2413
* plus the number of term parameters in `paramss` that come before that suffix.
2400
2414
*/
0 commit comments