Skip to content

Commit 8dcedc7

Browse files
committed
Rename contained to contained() to indicate side effect
1 parent ee1160c commit 8dcedc7

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ class ConsoleReporter(
2424
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
2525
val didPrint = m match {
2626
case m: Error =>
27-
printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m)))
27+
printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m)))
2828
if (ctx.settings.prompt.value) displayPrompt()
2929
true
3030
case m: ConditionalWarning if !m.enablingOption.value =>
3131
false
3232
case m =>
33-
printMessage(messageAndPos(m.contained, m.pos, diagnosticLevel(m)))
33+
printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m)))
3434
true
3535
}
3636

3737
if (didPrint && ctx.shouldExplain(m))
38-
printMessage(explanation(m.contained))
39-
else if (didPrint && m.contained.explanation.nonEmpty)
38+
printMessage(explanation(m.contained()))
39+
else if (didPrint && m.contained().explanation.nonEmpty)
4040
printMessage("\nlonger explanation available when compiling with `-explain`")
4141
}
4242

compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object MessageContainer {
1515
implicit class MessageContext(val c: Context) extends AnyVal {
1616
def shouldExplain(cont: MessageContainer): Boolean = {
1717
implicit val ctx = c
18-
cont.contained.explanation match {
18+
cont.contained().explanation match {
1919
case "" => false
2020
case _ => ctx.settings.explain.value
2121
}
@@ -39,7 +39,7 @@ class MessageContainer(
3939
/** The message to report */
4040
def message: String = {
4141
if (myMsg == null) {
42-
myMsg = contained.msg.replaceAll("\u001B\\[[;\\d]*m", "")
42+
myMsg = contained().msg.replaceAll("\u001B\\[[;\\d]*m", "")
4343
if (myMsg.contains(nonSensicalStartTag)) {
4444
myIsNonSensical = true
4545
// myMsg might be composed of several d"..." invocations -> nested
@@ -53,7 +53,8 @@ class MessageContainer(
5353
myMsg
5454
}
5555

56-
def contained: Message = {
56+
/** This function forces the contained message and returns it */
57+
def contained(): Message = {
5758
if (myContained == null)
5859
myContained = msgFn
5960

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait ErrorMessagesTest extends DottyTest {
4040

4141
def doReport(m: MessageContainer)(implicit ctx: Context) = {
4242
capturedContext = ctx
43-
buffer append m.contained
43+
buffer append m.contained()
4444
}
4545

4646
def toReport: Report =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
4949

5050
/** Prints the message with the given position indication. */
5151
def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
52-
val msg = messageAndPos(m.contained, m.pos, diagnosticLevel(m))
52+
val msg = messageAndPos(m.contained(), m.pos, diagnosticLevel(m))
5353
val extraInfo = inlineInfo(m.pos)
5454

5555
if (m.level >= logLevel) {
@@ -63,7 +63,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
6363

6464
override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
6565
// Here we add extra information that we should know about the error message
66-
val extra = m.contained match {
66+
val extra = m.contained() match {
6767
case pm: PatternMatchExhaustivity => s": ${pm.uncovered}"
6868
case _ => ""
6969
}
@@ -120,7 +120,7 @@ object TestReporter {
120120
/** Prints the message with the given position indication in a simplified manner */
121121
override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
122122
def report() = {
123-
val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
123+
val msg = s"${m.pos.line + 1}: " + m.contained().kind + extra
124124
val extraInfo = inlineInfo(m.pos)
125125

126126
writer.println(msg)

0 commit comments

Comments
 (0)