@@ -16,7 +16,7 @@ import printing.Formatting
1616import ErrorMessageID ._
1717import ast .Trees
1818import config .{Feature , ScalaVersion }
19- import typer .ErrorReporting .err
19+ import typer .ErrorReporting .{ err , matchReductionAddendum }
2020import typer .ProtoTypes .ViewProto
2121import scala .util .control .NonFatal
2222import StdNames .nme
@@ -45,22 +45,15 @@ import transform.SymUtils._
4545 abstract class TypeMsg (errorId : ErrorMessageID ) extends Message (errorId):
4646 def kind = " Type"
4747
48- abstract class TypeMismatchMsg (found : Type , expected : Type )(errorId : ErrorMessageID )(using Context ) extends Message (errorId):
48+ trait ShowMatchTrace (tps : Type * )(using Context ) extends Message :
49+ override def msgSuffix : String = matchReductionAddendum(tps* )
50+
51+ abstract class TypeMismatchMsg (found : Type , expected : Type )(errorId : ErrorMessageID )(using Context )
52+ extends Message (errorId), ShowMatchTrace (found, expected):
4953 def kind = " Type Mismatch"
5054 def explain = err.whyNoMatchStr(found, expected)
5155 override def canExplain = true
5256
53- override def msgSuffix : String =
54- val collectMatchTrace = new TypeAccumulator [String ]:
55- def apply (s : String , tp : Type ): String =
56- if s.nonEmpty then s
57- else tp match
58- case tp : AppliedType if tp.isMatchAlias => MatchTypeTrace .record(tp.tryNormalize)
59- case tp : MatchType => MatchTypeTrace .record(tp.tryNormalize)
60- case _ => foldOver(s, tp)
61- collectMatchTrace(collectMatchTrace(" " , found), expected)
62- end TypeMismatchMsg
63-
6457 abstract class NamingMsg (errorId : ErrorMessageID ) extends Message (errorId):
6558 def kind = " Naming"
6659
@@ -292,7 +285,7 @@ import transform.SymUtils._
292285 end TypeMismatch
293286
294287 class NotAMember (site : Type , val name : Name , selected : String , addendum : => String = " " )(using Context )
295- extends NotFoundMsg (NotAMemberID ) {
288+ extends NotFoundMsg (NotAMemberID ), ShowMatchTrace (site) {
296289 // println(i"site = $site, decls = ${site.decls}, source = ${site.typeSymbol.sourceFile}") //DEBUG
297290
298291 def msg = {
0 commit comments