File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 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 {
21012101 else defn.FunctionOf (commonParamTypes, WildcardType )
21022102 overload.println(i " pretype arg $arg with expected type $commonFormal" )
21032103 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+ }
21052109 }
21062110 recur(altFormals.map(_.tail), args1)
21072111 case _ =>
Original file line number Diff line number Diff line change @@ -424,6 +424,10 @@ object ProtoTypes {
424424 if (t == null ) NoType else t.tpe
425425 }
426426
427+ /** Cache the typed argument */
428+ def cacheArg (arg : untpd.Tree , targ : Tree ) =
429+ state.typedArg = state.typedArg.updated(arg, targ)
430+
427431 /** The same proto-type but with all arguments combined in a single tuple */
428432 def tupledDual : FunProto = state.tupledDual match {
429433 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