Skip to content

Commit 8f080a5

Browse files
authored
Merge pull request #4262 from dotty-staging/fix/typerstate-test
Fix reporter reuse in TyperState#test
2 parents 25de18d + 202b967 commit 8f080a5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TyperState(previous: TyperState /* | Null */) {
100100
def uncommittedAncestor: TyperState =
101101
if (isCommitted) previous.uncommittedAncestor else this
102102

103-
private[this] var testReporter: StoreReporter = null
103+
private[this] var testReporter: TestReporter = null
104104

105105
/** Test using `op`. If current typerstate is shared, run `op` in a fresh exploration
106106
* typerstate. If it is unshared, run `op` in current typerState, restoring typerState
@@ -116,15 +116,17 @@ class TyperState(previous: TyperState /* | Null */) {
116116
val savedCommitted = isCommitted
117117
myIsCommittable = false
118118
myReporter = {
119-
if (testReporter == null) {
120-
testReporter = new StoreReporter(reporter)
119+
if (testReporter == null || testReporter.inUse) {
120+
testReporter = new TestReporter(reporter)
121121
} else {
122122
testReporter.reset()
123123
}
124+
testReporter.inUse = true
124125
testReporter
125126
}
126127
try op(ctx)
127128
finally {
129+
testReporter.inUse = false
128130
resetConstraintTo(savedConstraint)
129131
myReporter = savedReporter
130132
myIsCommittable = savedCommittable
@@ -189,3 +191,14 @@ class TyperState(previous: TyperState /* | Null */) {
189191

190192
def stateChainStr: String = s"$this${if (previous == null) "" else previous.stateChainStr}"
191193
}
194+
195+
/** Temporary, reusable reporter used in TyperState#test */
196+
private class TestReporter(outer: Reporter) extends StoreReporter(outer) {
197+
/** Is this reporter currently used in a test? */
198+
var inUse = false
199+
200+
def reset() = {
201+
assert(!inUse, s"Cannot reset reporter currently in use: $this")
202+
infos = null
203+
}
204+
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import diagnostic.messages._
2020
*/
2121
class StoreReporter(outer: Reporter) extends Reporter {
2222

23-
private[this] var infos: mutable.ListBuffer[MessageContainer] = null
24-
25-
def reset() = infos = null
23+
protected[this] var infos: mutable.ListBuffer[MessageContainer] = null
2624

2725
def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
2826
typr.println(s">>>> StoredError: ${m.message}") // !!! DEBUG

0 commit comments

Comments
 (0)