Skip to content

Commit 0450ca0

Browse files
committed
Move errorsToBeReported variable to ContextBase
context.run is not always defined (e.g. for doctool).
1 parent 7e745f0 commit 0450ca0

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
144144
/** Actions that need to be performed at the end of the current compilation run */
145145
private var finalizeActions = mutable.ListBuffer[() => Unit]()
146146

147-
/** A variable that records that some error was reported in a globally committable context.
148-
* The error will not necessarlily be emitted, since it could still be that
149-
* the enclosing context will be aborted. The variable is used as a smoke test
150-
* to turn off assertions that might be wrong if the program is erroneous. To
151-
* just test for `ctx.reporter.errorsReported` is not always enough, since it
152-
* could be that the context in which the assertion is tested is a completer context
153-
* that's different from the context where the error was reported. See i13218.scala
154-
* for a test.
155-
*/
156-
var errorsToBeReported = false
157-
158147
def compile(files: List[AbstractFile]): Unit =
159148
try
160149
val sources = files.map(runContext.getSource(_))

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,17 @@ object Contexts {
929929
/** Flag to suppress inlining, set after overflow */
930930
private[dotc] var stopInlining: Boolean = false
931931

932+
/** A variable that records that some error was reported in a globally committable context.
933+
* The error will not necessarlily be emitted, since it could still be that
934+
* the enclosing context will be aborted. The variable is used as a smoke test
935+
* to turn off assertions that might be wrong if the program is erroneous. To
936+
* just test for `ctx.reporter.errorsReported` is not always enough, since it
937+
* could be that the context in which the assertion is tested is a completer context
938+
* that's different from the context where the error was reported. See i13218.scala
939+
* for a test.
940+
*/
941+
private[dotc] var errorsToBeReported = false
942+
932943
// Reporters state
933944
private[dotc] var indent: Int = 0
934945

@@ -958,6 +969,7 @@ object Contexts {
958969
uniqueNamedTypes.clear()
959970
emptyTypeBounds = null
960971
emptyWildcardBounds = null
972+
errorsToBeReported = false
961973
errorTypeMsg.clear()
962974
sources.clear()
963975
files.clear()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ abstract class Reporter extends interfaces.ReporterResult {
158158
errors = dia :: errors
159159
_errorCount += 1
160160
if ctx.typerState.isGlobalCommittable then
161-
ctx.run.errorsToBeReported = true
161+
ctx.base.errorsToBeReported = true
162162
case dia: Info => // nothing to do here
163163
// match error if d is something else
164164

compiler/src/dotty/tools/dotc/util/Attachment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object Attachment {
117117
}
118118

119119
final def pushAttachment[V](key: Key[V], value: V)(using ctx: Context): Unit = {
120-
assert(!hasAttachment(key) || ctx.run.errorsToBeReported, s"duplicate attachment for key $key")
120+
assert(!hasAttachment(key) || ctx.base.errorsToBeReported, s"duplicate attachment for key $key")
121121
next = new Link(key, value, next)
122122
}
123123

0 commit comments

Comments
 (0)