File tree 3 files changed +23
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -2101,7 +2101,11 @@ trait Applications extends Compatibility {
2101
2101
else defn.FunctionOf (commonParamTypes, WildcardType )
2102
2102
overload.println(i " pretype arg $arg with expected type $commonFormal" )
2103
2103
if (commonParamTypes.forall(isFullyDefined(_, ForceDegree .flipBottom)))
2104
- withMode(Mode .ImplicitsEnabled )(pt.typedArg(arg, commonFormal))
2104
+ withMode(Mode .ImplicitsEnabled ) {
2105
+ // We can cache the adapted argument here because the expected type
2106
+ // is a common type shared by all overloading candidates.
2107
+ pt.cacheArg(arg, pt.typedArg(arg, commonFormal))
2108
+ }
2105
2109
}
2106
2110
recur(altFormals.map(_.tail), args1)
2107
2111
case _ =>
Original file line number Diff line number Diff line change @@ -424,6 +424,10 @@ object ProtoTypes {
424
424
if (t == null ) NoType else t.tpe
425
425
}
426
426
427
+ /** Cache the typed argument */
428
+ def cacheArg (arg : untpd.Tree , targ : Tree ) =
429
+ state.typedArg = state.typedArg.updated(arg, targ)
430
+
427
431
/** The same proto-type but with all arguments combined in a single tuple */
428
432
def tupledDual : FunProto = state.tupledDual match {
429
433
case pt : FunProto =>
Original file line number Diff line number Diff line change
1
+ class Test :
2
+ def foo (a : Int , b : Int ) = a + b
3
+
4
+ Map (1 -> 2 ).map(foo _)
5
+ Map (1 -> 2 ).map(foo)
6
+
7
+ class Test2 :
8
+ def foo (a : Int , b : Int ) = a + b
9
+
10
+ def bar (f : ((Int , Int )) => Int ) = " ok"
11
+ def bar (f : ((Int , Int )) => String )(using Int ) = " ok"
12
+
13
+ bar(foo)
14
+ bar(foo _)
You can’t perform that action at this time.
0 commit comments