Skip to content

Fix reporter reuse in TyperState#test #4262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TyperState(previous: TyperState /* | Null */) {
def uncommittedAncestor: TyperState =
if (isCommitted) previous.uncommittedAncestor else this

private[this] var testReporter: StoreReporter = null
private[this] var testReporter: TestReporter = null

/** Test using `op`. If current typerstate is shared, run `op` in a fresh exploration
* typerstate. If it is unshared, run `op` in current typerState, restoring typerState
Expand All @@ -116,15 +116,17 @@ class TyperState(previous: TyperState /* | Null */) {
val savedCommitted = isCommitted
myIsCommittable = false
myReporter = {
if (testReporter == null) {
testReporter = new StoreReporter(reporter)
if (testReporter == null || testReporter.inUse) {
testReporter = new TestReporter(reporter)
} else {
testReporter.reset()
}
testReporter.inUse = true
testReporter
}
try op(ctx)
finally {
testReporter.inUse = false
resetConstraintTo(savedConstraint)
myReporter = savedReporter
myIsCommittable = savedCommittable
Expand Down Expand Up @@ -189,3 +191,14 @@ class TyperState(previous: TyperState /* | Null */) {

def stateChainStr: String = s"$this${if (previous == null) "" else previous.stateChainStr}"
}

/** Temporary, reusable reporter used in TyperState#test */
private class TestReporter(outer: Reporter) extends StoreReporter(outer) {
/** Is this reporter currently used in a test? */
var inUse = false

def reset() = {
assert(!inUse, s"Cannot reset reporter currently in use: $this")
infos = null
}
}
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import diagnostic.messages._
*/
class StoreReporter(outer: Reporter) extends Reporter {

private[this] var infos: mutable.ListBuffer[MessageContainer] = null

def reset() = infos = null
protected[this] var infos: mutable.ListBuffer[MessageContainer] = null

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