Skip to content

Commit 870fd44

Browse files
committed
Use displayPrompt
1 parent 0a38214 commit 870fd44

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import core.Flags.{JavaDefined, Extension}
1010
import core.StdNames.nme
1111
import annotation.constructorOnly
1212
import annotation.internal.sharable
13+
import reporting.Reporter
14+
15+
import java.io.{ PrintWriter }
1316

1417
/** A base class for things that have positions (currently: modifiers and trees)
1518
*/
@@ -24,7 +27,10 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
2427
def uniqueId: Int = myUniqueId
2528

2629
def uniqueId_=(id: Int): Unit = {
27-
if (Positioned.debugId == id) ???
30+
if (Positioned.debugId == id) {
31+
println(s"Debug tree (id=${Positioned.debugId}) creation \n$this\n")
32+
Reporter.displayPrompt(Console.in, new PrintWriter(Console.err, true))
33+
}
2834
myUniqueId = id
2935
}
3036

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConsoleReporter(
2525
val didPrint = m match {
2626
case m: Error =>
2727
printMessage(messageAndPos(m.contained(), m.pos, diagnosticLevel(m)))
28-
if (ctx.settings.Xprompt.value) displayPrompt()
28+
if (ctx.settings.Xprompt.value) Reporter.displayPrompt(reader, writer)
2929
true
3030
case m: ConditionalWarning if !m.enablingOption.value =>
3131
false
@@ -40,28 +40,5 @@ class ConsoleReporter(
4040
printMessage("\nlonger explanation available when compiling with `-explain`")
4141
}
4242

43-
/** Show prompt if `-Xprompt` is passed as a flag to the compiler */
44-
def displayPrompt(): Unit = {
45-
writer.println()
46-
writer.print("a)bort, s)tack, r)esume: ")
47-
writer.flush()
48-
if (reader != null) {
49-
def loop(): Unit = reader.read match {
50-
case 'a' | 'A' =>
51-
new Throwable().printStackTrace(writer)
52-
System.exit(1)
53-
case 's' | 'S' =>
54-
new Throwable().printStackTrace(writer)
55-
writer.println()
56-
writer.flush()
57-
case 'r' | 'R' =>
58-
()
59-
case _ =>
60-
loop()
61-
}
62-
loop()
63-
}
64-
}
65-
6643
override def flush()(implicit ctx: Context): Unit = { writer.flush() }
6744
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import core.Contexts._
88
import util.{SourcePosition, NoSourcePosition}
99
import core.Decorators.PhaseListDecorator
1010
import collection.mutable
11-
import java.lang.System.currentTimeMillis
1211
import core.Mode
1312
import dotty.tools.dotc.core.Symbols.{Symbol, NoSymbol}
1413
import diagnostic.messages._
1514
import diagnostic._
1615
import ast.{tpd, Trees}
1716
import Message._
1817

18+
import java.lang.System.currentTimeMillis
19+
import java.io.{ BufferedReader, PrintWriter }
20+
21+
1922
object Reporter {
2023
/** Convert a SimpleReporter into a real Reporter */
2124
def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
@@ -37,6 +40,29 @@ object Reporter {
3740

3841
private val defaultIncompleteHandler: ErrorHandler =
3942
(mc, ctx) => ctx.reporter.report(mc)(ctx)
43+
44+
/** Show prompt if `-Xprompt` is passed as a flag to the compiler */
45+
def displayPrompt(reader: BufferedReader, writer: PrintWriter): Unit = {
46+
writer.println()
47+
writer.print("a)bort, s)tack, r)esume: ")
48+
writer.flush()
49+
if (reader != null) {
50+
def loop(): Unit = reader.read match {
51+
case 'a' | 'A' =>
52+
new Throwable().printStackTrace(writer)
53+
System.exit(1)
54+
case 's' | 'S' =>
55+
new Throwable().printStackTrace(writer)
56+
writer.println()
57+
writer.flush()
58+
case 'r' | 'R' =>
59+
()
60+
case _ =>
61+
loop()
62+
}
63+
loop()
64+
}
65+
}
4066
}
4167

4268
trait Reporting { this: Context =>

0 commit comments

Comments
 (0)