Skip to content

Commit 8fa10ee

Browse files
mbovelWojciechMazur
authored andcommitted
Move maybeAddInsertedApplyNote to outer scope, add explicit types
[Cherry-picked 1f06af1]
1 parent 561b46e commit 8fa10ee

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,34 @@ trait Applications extends Compatibility {
10201020
}
10211021
}
10221022

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+
10231051
fun1.tpe match {
10241052
case err: ErrorType => cpy.Apply(tree)(fun1, proto.typedArgs()).withType(err)
10251053
case TryDynamicCallType =>
@@ -1081,35 +1109,10 @@ trait Applications extends Compatibility {
10811109
} {
10821110
(failedVal, failedState) =>
10831111
def fail =
1084-
insertedApplyNote()
1112+
maybeAddInsertedApplyNote(failedState, fun1)
10851113
failedState.commit()
10861114
failedVal
10871115

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-
11131116
// Try once with original prototype and once (if different) with tupled one.
11141117
// The reason we need to try both is that the decision whether to use tupled
11151118
// or not was already taken but might have to be revised when an implicit

0 commit comments

Comments
 (0)