@@ -1024,6 +1024,34 @@ trait Applications extends Compatibility {
10241024 }
10251025 }
10261026
1027+ /** If the applied function is an automatically inserted `apply`
1028+ * method and one of its arguments has a type mismatch , append
1029+ * a note to the error message that explains where the required
1030+ * type comes from. See #19680 and associated test case.
1031+ */
1032+ def maybeAddInsertedApplyNote (failedState : TyperState , fun1 : Tree )(using Context ): Unit =
1033+ if fun1.symbol.name == nme.apply && fun1.span.isSynthetic then
1034+ fun1 match
1035+ case Select (qualifier, _) =>
1036+ def mapMessage (dia : Diagnostic ): Diagnostic =
1037+ dia match
1038+ case dia : Diagnostic .Error =>
1039+ dia.msg match
1040+ case msg : TypeMismatch =>
1041+ msg.inTree match
1042+ case Some (arg) if tree.args.exists(_.span == arg.span) =>
1043+ val noteText =
1044+ i """ The required type comes from a parameter of the automatically
1045+ |inserted `apply` method of ` ${qualifier.tpe}`,
1046+ |which is the type of ` ${qualifier.show}`. """ .stripMargin
1047+ Diagnostic .Error (msg.appendExplanation(" \n\n " + noteText), dia.pos)
1048+ case _ => dia
1049+ case msg => dia
1050+ case dia => dia
1051+ failedState.reporter.mapBufferedMessages(mapMessage)
1052+ case _ => ()
1053+ else ()
1054+
10271055 fun1.tpe match {
10281056 case err : ErrorType => cpy.Apply (tree)(fun1, proto.typedArgs()).withType(err)
10291057 case TryDynamicCallType =>
@@ -1085,35 +1113,10 @@ trait Applications extends Compatibility {
10851113 } {
10861114 (failedVal, failedState) =>
10871115 def fail =
1088- insertedApplyNote( )
1116+ maybeAddInsertedApplyNote(failedState, fun1 )
10891117 failedState.commit()
10901118 failedVal
10911119
1092- /** If the applied function is an automatically inserted `apply`
1093- * method and one of its arguments has a type mismatch , append
1094- * a note to the error message that explains where the required
1095- * type comes from. See #19680 and associated test case.
1096- */
1097- def insertedApplyNote () =
1098- if fun1.symbol.name == nme.apply && fun1.span.isSynthetic then
1099- fun1 match
1100- case Select (qualifier, _) =>
1101- failedState.reporter.mapBufferedMessages:
1102- case dia : Diagnostic .Error =>
1103- dia.msg match
1104- case msg : TypeMismatch =>
1105- msg.inTree match
1106- case Some (arg) if tree.args.exists(_.span == arg.span) =>
1107- val noteText =
1108- i """ The required type comes from a parameter of the automatically
1109- |inserted `apply` method of ` ${qualifier.tpe}`,
1110- |which is the type of ` ${qualifier.show}`. """ .stripMargin
1111- Diagnostic .Error (msg.appendExplanation(" \n\n " + noteText), dia.pos)
1112- case _ => dia
1113- case msg => dia
1114- case dia => dia
1115- case _ => ()
1116-
11171120 // Try once with original prototype and once (if different) with tupled one.
11181121 // The reason we need to try both is that the decision whether to use tupled
11191122 // or not was already taken but might have to be revised when an implicit
0 commit comments