Skip to content

Commit b21d883

Browse files
committed
Simplify failure addendum
1 parent 2d0e373 commit b21d883

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ object Diagnostic:
8585
pos: SourcePosition
8686
) extends Warning(msg, pos)
8787

88+
def unapply(d: Diagnostic): (Message, SourcePosition, Int) = (d.msg, d.pos, d.level)
89+
8890
class Diagnostic(
8991
val msg: Message,
9092
val pos: SourcePosition,

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,23 +1105,16 @@ trait Applications extends Compatibility {
11051105
if fun1.symbol.name == nme.apply && fun1.span.isSynthetic then
11061106
fun1 match
11071107
case Select(qualifier, _) =>
1108-
def mapMessage(dia: Diagnostic): Diagnostic =
1109-
dia match
1110-
case dia: Diagnostic.Error =>
1111-
dia.msg match
1112-
case msg: TypeMismatch =>
1113-
msg.inTree match
1114-
case Some(arg) if tree.args.exists(_.span == arg.span) =>
1115-
val noteText =
1116-
i"""The required type comes from a parameter of the automatically
1117-
|inserted `apply` method of `${qualifier.tpe}`.""".stripMargin
1118-
Diagnostic.Error(msg.appendExplanation("\n\n" + noteText), dia.pos)
1119-
case _ => dia
1120-
case msg => dia
1121-
case dia => dia
1122-
failedState.reporter.mapBufferedMessages(mapMessage)
1123-
case _ => ()
1124-
else ()
1108+
import dotty.tools.dotc.interfaces.Diagnostic.ERROR
1109+
failedState.reporter.mapBufferedMessages:
1110+
case Diagnostic(msg: TypeMismatch, pos, ERROR)
1111+
if msg.inTree.exists(t => tree.args.exists(_.span == t.span)) =>
1112+
val noteText =
1113+
i"""The required type comes from a parameter of the automatically
1114+
|inserted `apply` method of `${qualifier.tpe}`.""".stripMargin
1115+
Diagnostic.Error(msg.appendExplanation("\n\n" + noteText), pos)
1116+
case dia => dia
1117+
case _ =>
11251118

11261119
fun1.tpe match {
11271120
case err: ErrorType => cpy.Apply(tree)(fun1, proto.typedArgs()).withType(err)

0 commit comments

Comments
 (0)