Skip to content

Commit f5c30a9

Browse files
committed
Convert reporting classes
1 parent e71a167 commit f5c30a9

18 files changed

+182
-182
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConsoleReporter(
2020
def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }
2121

2222
/** Prints the message with the given position indication. */
23-
def doReport(dia: Diagnostic)(implicit ctx: Context): Unit = {
23+
def doReport(dia: Diagnostic)(using Context): Unit = {
2424
val didPrint = dia match {
2525
case dia: Error =>
2626
printMessage(messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia)))
@@ -39,5 +39,5 @@ class ConsoleReporter(
3939
printMessage("\nlonger explanation available when compiling with `-explain`")
4040
}
4141

42-
override def flush()(implicit ctx: Context): Unit = { writer.flush() }
42+
override def flush()(using Context): Unit = { writer.flush() }
4343
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ object Diagnostic:
4545
msg: Message,
4646
pos: SourcePosition
4747
) extends Warning(msg, pos) {
48-
def enablingOption(implicit ctx: Context): Setting[Boolean]
48+
def enablingOption(using Context): Setting[Boolean]
4949
}
5050

5151
class FeatureWarning(
5252
msg: Message,
5353
pos: SourcePosition
5454
) extends ConditionalWarning(msg, pos) {
55-
def enablingOption(implicit ctx: Context): Setting[Boolean] = ctx.settings.feature
55+
def enablingOption(using Context): Setting[Boolean] = ctx.settings.feature
5656
}
5757

5858
class UncheckedWarning(
5959
msg: Message,
6060
pos: SourcePosition
6161
) extends ConditionalWarning(msg, pos) {
62-
def enablingOption(implicit ctx: Context): Setting[Boolean] = ctx.settings.unchecked
62+
def enablingOption(using Context): Setting[Boolean] = ctx.settings.unchecked
6363
}
6464

6565
class DeprecationWarning(
6666
msg: Message,
6767
pos: SourcePosition
6868
) extends ConditionalWarning(msg, pos) {
69-
def enablingOption(implicit ctx: Context): Setting[Boolean] = ctx.settings.deprecation
69+
def enablingOption(using Context): Setting[Boolean] = ctx.settings.deprecation
7070
}
7171

7272
class MigrationWarning(
7373
msg: Message,
7474
pos: SourcePosition
7575
) extends Warning(msg, pos) {
76-
def enablingOption(implicit ctx: Context): Setting[Boolean] = ctx.settings.migration
76+
def enablingOption(using Context): Setting[Boolean] = ctx.settings.migration
7777
}
7878

7979
class Diagnostic(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait HideNonSensicalMessages extends Reporter {
1111
/** Hides non-sensical messages, unless we haven't reported any error yet or
1212
* `-Yshow-suppressed-errors` is set.
1313
*/
14-
override def isHidden(dia: Diagnostic)(implicit ctx: Context): Boolean =
14+
override def isHidden(dia: Diagnostic)(using Context): Boolean =
1515
super.isHidden(dia) || {
1616
dia.msg.isNonSensical &&
1717
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait MessageRendering {
3030
*
3131
* @return a list of strings with inline locations
3232
*/
33-
def outer(pos: SourcePosition, prefix: String)(implicit ctx: Context): List[String] =
33+
def outer(pos: SourcePosition, prefix: String)(using Context): List[String] =
3434
if (pos.outer.exists)
3535
i"$prefix| This location contains code that was inlined from $pos" ::
3636
outer(pos.outer, prefix)
@@ -41,7 +41,7 @@ trait MessageRendering {
4141
*
4242
* @return (lines before error, lines after error, line numbers offset)
4343
*/
44-
def sourceLines(pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): (List[String], List[String], Int) = {
44+
def sourceLines(pos: SourcePosition, diagnosticLevel: String)(using Context): (List[String], List[String], Int) = {
4545
assert(pos.exists && pos.source.file.exists)
4646
var maxLen = Int.MinValue
4747
def render(offsetAndLine: (Int, String)): String = {
@@ -78,7 +78,7 @@ trait MessageRendering {
7878
}
7979

8080
/** The column markers aligned under the error */
81-
def columnMarker(pos: SourcePosition, offset: Int, diagnosticLevel: String)(implicit ctx: Context): String = {
81+
def columnMarker(pos: SourcePosition, offset: Int, diagnosticLevel: String)(using Context): String = {
8282
val prefix = " " * (offset - 1)
8383
val padding = pos.startColumnPadding
8484
val carets = hl(diagnosticLevel) {
@@ -93,7 +93,7 @@ trait MessageRendering {
9393
*
9494
* @return aligned error message
9595
*/
96-
def errorMsg(pos: SourcePosition, msg: String, offset: Int)(implicit ctx: Context): String = {
96+
def errorMsg(pos: SourcePosition, msg: String, offset: Int)(using Context): String = {
9797
val padding = msg.linesIterator.foldLeft(pos.startColumnPadding) { (pad, line) =>
9898
val lineLength = stripColor(line).length
9999
val maxPad = math.max(0, ctx.settings.pageWidth.value - offset - lineLength) - offset
@@ -111,7 +111,7 @@ trait MessageRendering {
111111
*
112112
* @return separator containing error location and kind
113113
*/
114-
def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context): String =
114+
def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String =
115115
if (pos.exists) hl(diagnosticLevel)({
116116
val pos1 = pos.nonInlined
117117
val file =
@@ -131,7 +131,7 @@ trait MessageRendering {
131131
}) else ""
132132

133133
/** Explanation rendered under "Explanation" header */
134-
def explanation(m: Message)(implicit ctx: Context): String = {
134+
def explanation(m: Message)(using Context): String = {
135135
val sb = new StringBuilder(
136136
s"""|
137137
|${Blue("Explanation").show}
@@ -143,7 +143,7 @@ trait MessageRendering {
143143
}
144144

145145
/** The whole message rendered from `msg` */
146-
def messageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(implicit ctx: Context): String = {
146+
def messageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(using Context): String = {
147147
val sb = mutable.StringBuilder()
148148
val posString = posStr(pos, diagnosticLevel, msg)
149149
if (posString.nonEmpty) sb.append(posString).append(EOL)
@@ -158,7 +158,7 @@ trait MessageRendering {
158158
sb.toString
159159
}
160160

161-
def hl(diagnosticLevel: String)(str: String)(implicit ctx: Context): String = diagnosticLevel match {
161+
def hl(diagnosticLevel: String)(str: String)(using Context): String = diagnosticLevel match {
162162
case "Info" => Blue(str).show
163163
case "Error" => Red(str).show
164164
case _ =>

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Reporter {
2626
/** Convert a SimpleReporter into a real Reporter */
2727
def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
2828
new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
29-
override def doReport(dia: Diagnostic)(implicit ctx: Context): Unit = dia match {
29+
override def doReport(dia: Diagnostic)(using Context): Unit = dia match {
3030
case dia: ConditionalWarning if !dia.enablingOption.value =>
3131
case _ =>
3232
simple.report(dia)
@@ -35,14 +35,14 @@ object Reporter {
3535

3636
/** A reporter that ignores reports, and doesn't record errors */
3737
@sharable object NoReporter extends Reporter {
38-
def doReport(dia: Diagnostic)(implicit ctx: Context): Unit = ()
39-
override def report(dia: Diagnostic)(implicit ctx: Context): Unit = ()
38+
def doReport(dia: Diagnostic)(using Context): Unit = ()
39+
override def report(dia: Diagnostic)(using Context): Unit = ()
4040
}
4141

4242
type ErrorHandler = (Diagnostic, Context) => Unit
4343

4444
private val defaultIncompleteHandler: ErrorHandler =
45-
(mc, ctx) => ctx.reporter.report(mc)(ctx)
45+
(mc, ctx) => ctx.reporter.report(mc)(using ctx)
4646

4747
/** Show prompt if `-Xprompt` is passed as a flag to the compiler */
4848
def displayPrompt(reader: BufferedReader, writer: PrintWriter): Unit = {
@@ -145,8 +145,8 @@ trait Reporting { thisCtx: Context =>
145145
def restrictionError(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
146146
error(msg.mapMsg("Implementation restriction: " + _), pos)
147147

148-
def incompleteInputError(msg: Message, pos: SourcePosition = NoSourcePosition)(implicit ctx: Context): Unit =
149-
reporter.incomplete(new Error(msg, pos))(ctx)
148+
def incompleteInputError(msg: Message, pos: SourcePosition = NoSourcePosition)(using Context): Unit =
149+
reporter.incomplete(new Error(msg, pos))(using ctx)
150150

151151
/** Log msg if settings.log contains the current phase.
152152
* See [[config.CompilerCommand#explainAdvanced]] for the exact meaning of
@@ -175,7 +175,7 @@ trait Reporting { thisCtx: Context =>
175175
def debugwarn(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
176176
if (thisCtx.settings.Ydebug.value) warning(msg, pos)
177177

178-
private def addInlineds(pos: SourcePosition)(implicit ctx: Context) = {
178+
private def addInlineds(pos: SourcePosition)(using Context) = {
179179
def recur(pos: SourcePosition, inlineds: List[Trees.Tree[?]]): SourcePosition = inlineds match {
180180
case inlined :: inlineds1 => pos.withOuter(recur(inlined.sourcePos, inlineds1))
181181
case Nil => pos
@@ -192,7 +192,7 @@ abstract class Reporter extends interfaces.ReporterResult {
192192
import Reporter._
193193

194194
/** Report a diagnostic */
195-
def doReport(dia: Diagnostic)(implicit ctx: Context): Unit
195+
def doReport(dia: Diagnostic)(using Context): Unit
196196

197197
/** Whether very long lines can be truncated. This exists so important
198198
* debugging information (like printing the classpath) is not rendered
@@ -261,9 +261,9 @@ abstract class Reporter extends interfaces.ReporterResult {
261261

262262
var unreportedWarnings: Map[String, Int] = Map.empty
263263

264-
def report(dia: Diagnostic)(implicit ctx: Context): Unit =
264+
def report(dia: Diagnostic)(using Context): Unit =
265265
if (!isHidden(dia)) {
266-
doReport(dia)(ctx.addMode(Mode.Printing))
266+
doReport(dia)(using ctx.addMode(Mode.Printing))
267267
dia match {
268268
case dia: ConditionalWarning if !dia.enablingOption.value =>
269269
val key = dia.enablingOption.name
@@ -278,7 +278,7 @@ abstract class Reporter extends interfaces.ReporterResult {
278278
}
279279
}
280280

281-
def incomplete(dia: Diagnostic)(implicit ctx: Context): Unit =
281+
def incomplete(dia: Diagnostic)(using Context): Unit =
282282
incompleteHandler(dia, ctx)
283283

284284
/** Summary of warnings and errors */
@@ -294,7 +294,7 @@ abstract class Reporter extends interfaces.ReporterResult {
294294
}
295295

296296
/** Print the summary of warnings and errors */
297-
def printSummary(implicit ctx: Context): Unit = {
297+
def printSummary(using Context): Unit = {
298298
val s = summary
299299
if (s != "") ctx.echo(s)
300300
}
@@ -307,7 +307,7 @@ abstract class Reporter extends interfaces.ReporterResult {
307307
}
308308

309309
/** Should this diagnostic not be reported at all? */
310-
def isHidden(dia: Diagnostic)(implicit ctx: Context): Boolean =
310+
def isHidden(dia: Diagnostic)(using Context): Boolean =
311311
ctx.mode.is(Mode.Printing)
312312

313313
/** Does this reporter contain errors that have yet to be reported by its outer reporter ?
@@ -316,10 +316,10 @@ abstract class Reporter extends interfaces.ReporterResult {
316316
def hasUnreportedErrors: Boolean = false
317317

318318
/** If this reporter buffers messages, remove and return all buffered messages. */
319-
def removeBufferedMessages(implicit ctx: Context): List[Diagnostic] = Nil
319+
def removeBufferedMessages(using Context): List[Diagnostic] = Nil
320320

321321
/** Issue all error messages in this reporter to next outer one, or make sure they are written. */
322-
def flush()(implicit ctx: Context): Unit =
322+
def flush()(using Context): Unit =
323323
removeBufferedMessages.foreach(ctx.reporter.report)
324324

325325
/** If this reporter buffers messages, all buffered messages, otherwise Nil */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StoreReporter(outer: Reporter) extends Reporter {
2121

2222
protected var infos: mutable.ListBuffer[Diagnostic] = null
2323

24-
def doReport(dia: Diagnostic)(implicit ctx: Context): Unit = {
24+
def doReport(dia: Diagnostic)(using Context): Unit = {
2525
typr.println(s">>>> StoredError: ${dia.message}") // !!! DEBUG
2626
if (infos == null) infos = new mutable.ListBuffer
2727
infos += dia
@@ -33,7 +33,7 @@ class StoreReporter(outer: Reporter) extends Reporter {
3333
override def hasStickyErrors: Boolean =
3434
infos != null && infos.exists(_.isInstanceOf[StickyError])
3535

36-
override def removeBufferedMessages(implicit ctx: Context): List[Diagnostic] =
36+
override def removeBufferedMessages(using Context): List[Diagnostic] =
3737
if (infos != null) try infos.toList finally infos = null
3838
else Nil
3939

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Diagnostic.Error
1010
* info to the underlying reporter.
1111
*/
1212
class ThrowingReporter(reportInfo: Reporter) extends Reporter {
13-
def doReport(dia: Diagnostic)(implicit ctx: Context): Unit = dia match {
13+
def doReport(dia: Diagnostic)(using Context): Unit = dia match {
1414
case _: Error => throw dia
1515
case _ => reportInfo.doReport(dia)
1616
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait UniqueMessagePositions extends Reporter {
1515
/** Logs a position and returns true if it was already logged.
1616
* @note Two positions are considered identical for logging if they have the same point.
1717
*/
18-
override def isHidden(dia: Diagnostic)(implicit ctx: Context): Boolean =
18+
override def isHidden(dia: Diagnostic)(using Context): Boolean =
1919
super.isHidden(dia) || {
2020
dia.pos.exists && !ctx.settings.YshowSuppressedErrors.value && {
2121
var shouldHide = false

0 commit comments

Comments
 (0)