@@ -16,7 +16,7 @@ import printing.Formatting
16
16
import ErrorMessageID ._
17
17
import ast .Trees
18
18
import config .{Feature , ScalaVersion }
19
- import typer .ErrorReporting .err
19
+ import typer .ErrorReporting .{ err , matchReductionAddendum }
20
20
import typer .ProtoTypes .ViewProto
21
21
import scala .util .control .NonFatal
22
22
import StdNames .nme
@@ -45,22 +45,15 @@ import transform.SymUtils._
45
45
abstract class TypeMsg (errorId : ErrorMessageID ) extends Message (errorId):
46
46
def kind = " Type"
47
47
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):
49
53
def kind = " Type Mismatch"
50
54
def explain = err.whyNoMatchStr(found, expected)
51
55
override def canExplain = true
52
56
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
-
64
57
abstract class NamingMsg (errorId : ErrorMessageID ) extends Message (errorId):
65
58
def kind = " Naming"
66
59
@@ -292,7 +285,7 @@ import transform.SymUtils._
292
285
end TypeMismatch
293
286
294
287
class NotAMember (site : Type , val name : Name , selected : String , addendum : => String = " " )(using Context )
295
- extends NotFoundMsg (NotAMemberID ) {
288
+ extends NotFoundMsg (NotAMemberID ), ShowMatchTrace (site) {
296
289
// println(i"site = $site, decls = ${site.decls}, source = ${site.typeSymbol.sourceFile}") //DEBUG
297
290
298
291
def msg = {
0 commit comments