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