Skip to content

Commit 3ace887

Browse files
committed
Cleanups of Message
1 parent cdabf41 commit 3ace887

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ object Message:
3434
var nonSensical = false
3535
private var recordOK = disambiguate
3636

37-
def stopRecording() =
37+
/** Clear all entries and stop further entries to be added */
38+
def disable() =
39+
clear()
3840
recordOK = false
3941

4042
def record(str: String, isType: Boolean, entry: Recorded)(using Context): String = {
@@ -240,10 +242,10 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
240242
case msgPrinter: Message.Printer =>
241243
myIsNonSensical = msgPrinter.seen.nonSensical
242244
val addendum = explanations(msgPrinter.seen)
243-
msgPrinter.seen.clear()
244-
msgPrinter.seen.stopRecording()
245-
if addendum.isEmpty || !disambiguate then ""
246-
else "\n\n" ++ addendum
245+
msgPrinter.seen.disable()
246+
// Clear entries and stop futher recording so that messages containing the current
247+
// one don't repeat the explanations or use explanations from the msgPostscript.
248+
if addendum.isEmpty then "" else "\n\n" ++ addendum
247249
case _ =>
248250
""
249251

@@ -254,7 +256,7 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
254256
*/
255257
def canExplain: Boolean = explain.nonEmpty
256258

257-
var myIsNonSensical: Boolean = false
259+
private var myIsNonSensical: Boolean = false
258260

259261
/** A message is non-sensical if it contains references to internally
260262
* generated error types. Normally we want to suppress error messages
@@ -272,14 +274,14 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
272274
private def inMessageContext(disambiguate: Boolean)(op: Context ?=> String): String =
273275
if ctx eq NoContext then op
274276
else
275-
val (msgContext, msgPrinter: Message.Printer) = ctx.printer match
276-
case printer: Message.Printer => (ctx, printer)
277+
val msgContext = ctx.printer match
278+
case _: Message.Printer => ctx
277279
case _ =>
278280
val seen = Seen(disambiguate)
279281
val ctx1 = ctx.fresh.setPrinterFn(Message.Printer(seen, _))
280282
if !ctx1.property(MessageLimiter).isDefined then
281283
ctx1.setProperty(MessageLimiter, ErrorMessageLimiter())
282-
(ctx1, ctx1.printer.asInstanceOf[Message.Printer])
284+
ctx1
283285
op(using msgContext)
284286

285287
/** The message to report. <nonsensical> tags are filtered out */

0 commit comments

Comments
 (0)