Skip to content

Commit 5e152cb

Browse files
committed
messageAndPos takes Diagnostic parameter (refactoring only)
1 parent add86fa commit 5e152cb

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class ConsoleReporter(
2323
def doReport(dia: Diagnostic)(using Context): Unit = {
2424
dia match
2525
case dia: Error =>
26-
printMessage(messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia)))
26+
printMessage(messageAndPos(dia))
2727
if (ctx.settings.Xprompt.value) Reporter.displayPrompt(reader, writer)
2828
case dia =>
29-
printMessage(messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia)))
29+
printMessage(messageAndPos(dia))
3030

3131
if shouldExplain(dia) then
3232
printMessage(explanation(dia.msg))

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,17 @@ trait MessageRendering {
143143
}
144144

145145
/** The whole message rendered from `msg` */
146-
def messageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(using Context): String = {
146+
def messageAndPos(dia: Diagnostic)(using Context): String = {
147+
import dia._
148+
val levelString = diagnosticLevel(dia)
147149
val sb = mutable.StringBuilder()
148-
val posString = posStr(pos, diagnosticLevel, msg)
150+
val posString = posStr(pos, levelString, msg)
149151
if (posString.nonEmpty) sb.append(posString).append(EOL)
150152
if (pos.exists) {
151153
val pos1 = pos.nonInlined
152154
if (pos1.exists && pos1.source.file.exists) {
153-
val (srcBefore, srcAfter, offset) = sourceLines(pos1, diagnosticLevel)
154-
val marker = columnMarker(pos1, offset, diagnosticLevel)
155+
val (srcBefore, srcAfter, offset) = sourceLines(pos1, levelString)
156+
val marker = columnMarker(pos1, offset, levelString)
155157
val err = errorMsg(pos1, msg.message, offset)
156158
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL))
157159
}

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
128128
/** Formats errors using the `messageRenderer` */
129129
def formatError(dia: Diagnostic)(implicit state: State): Diagnostic =
130130
new Diagnostic(
131-
messageRenderer.messageAndPos(dia.msg, dia.pos, messageRenderer.diagnosticLevel(dia))(using state.context),
131+
messageRenderer.messageAndPos(dia)(using state.context),
132132
dia.pos,
133133
dia.level
134134
)

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
5353

5454
/** Prints the message with the given position indication. */
5555
def printMessageAndPos(dia: Diagnostic, extra: String)(using Context): Unit = {
56-
val msg = messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia))
56+
val msg = messageAndPos(dia)
5757
val extraInfo = inlineInfo(dia.pos)
5858

5959
if (dia.level >= logLevel) {

sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public void doReport(Diagnostic dia, Context ctx) {
3232
Severity severity = severityOf(dia.level());
3333
Position position = positionOf(dia.pos().nonInlined());
3434

35-
Message message = dia.msg();
3635
StringBuilder rendered = new StringBuilder();
37-
rendered.append(messageAndPos(message, dia.pos(), diagnosticLevel(dia), ctx));
36+
rendered.append(messageAndPos(dia, ctx));
37+
Message message = dia.msg();
3838
boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx);
3939
if (shouldExplain && !message.explanation().isEmpty()) {
4040
rendered.append(explanation(message, ctx));

0 commit comments

Comments
 (0)