@@ -1379,21 +1379,19 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1379
1379
}
1380
1380
1381
1381
/** Try to typecheck any arguments in `pt` that are function values missing a
1382
- * parameter type. The expected type for these arguments is the lub of the
1383
- * corresponding formal parameter types of all alternatives. Type variables
1384
- * in formal parameter types are replaced by wildcards. The result of the
1385
- * typecheck is stored in `pt`, to be retrieved when its `typedArgs` are selected.
1382
+ * parameter type. If the formal parameter types corresponding to a closure argument
1383
+ * all agree on their argument types, typecheck the argument with an expected
1384
+ * function or partial function type that contains these argument types,
1385
+ * The result of the typecheck is stored in `pt`, to be retrieved when its `typedArgs` are selected.
1386
1386
* The benefit of doing this is to allow idioms like this:
1387
1387
*
1388
1388
* def map(f: Char => Char): String = ???
1389
1389
* def map[U](f: Char => U): Seq[U] = ???
1390
1390
* map(x => x.toUpper)
1391
1391
*
1392
1392
* Without `pretypeArgs` we'd get a "missing parameter type" error for `x`.
1393
- * With `pretypeArgs`, we use the union of the two formal parameter types
1394
- * `Char => Char` and `Char => ?` as the expected type of the closure `x => x.toUpper`.
1395
- * That union is `Char => Char`, so we have an expected parameter type `Char`
1396
- * for `x`, and the code typechecks.
1393
+ * With `pretypeArgs`, we use the `Char => ?` as the expected type of the
1394
+ * closure `x => x.toUpper`, which makes the code typecheck.
1397
1395
*/
1398
1396
private def pretypeArgs (alts : List [TermRef ], pt : FunProto )(implicit ctx : Context ): Unit = {
1399
1397
def recur (altFormals : List [List [Type ]], args : List [untpd.Tree ]): Unit = args match {
0 commit comments