Skip to content

Commit 0dc2c3d

Browse files
authored
Merge pull request scala#5655 from som-snytt/issue/10102
SI-10102 REPL ignores sbt init errors
2 parents 085be56 + 4347dd9 commit 0dc2c3d

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

src/repl/scala/tools/nsc/InterpreterLoop.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package scala.tools.nsc
33
import interpreter._
44
import java.io._
55

6-
/** A compatibility stub.
6+
/** A compatibility stub for sbt.
77
*/
8-
@deprecated("Use a class in the scala.tools.nsc.interpreter package.", "2.9.0")
8+
@deprecated("Use scala.tools.nsc.interpreter.ILoop.", "2.9.0")
99
class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) extends ILoop(in0, out) {
1010
def this(in0: BufferedReader, out: PrintWriter) = this(Some(in0), out)
1111
def this() = this(None, new PrintWriter(scala.Console.out))
12+
13+
override protected final val isSbt = true
14+
15+
@deprecated("use `process` instead", "2.9.0")
16+
def main(settings: Settings): Unit = process(settings) //used by sbt
1217
}

src/repl/scala/tools/nsc/interpreter/ILoop.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ import Completion._
4141
* @author Lex Spoon
4242
* @version 1.2
4343
*/
44-
class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
45-
extends AnyRef
46-
with LoopCommands
47-
{
44+
class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) extends LoopCommands {
4845
def this(in0: BufferedReader, out: JPrintWriter) = this(Some(in0), out)
4946
def this() = this(None, new JPrintWriter(Console.out, true))
5047

@@ -57,6 +54,9 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
5754

5855
private var globalFuture: Future[Boolean] = _
5956

57+
// ignore silent sbt errors on init
58+
protected def isSbt: Boolean = false
59+
6060
/** Print a welcome message! */
6161
def printWelcome(): Unit = {
6262
Option(replProps.welcome) filter (!_.isEmpty) foreach echo
@@ -1048,8 +1048,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
10481048
//for (rs <- runnerSettings if rs.execute.isSetByUser) intp.printResults = false
10491049
}
10501050
intp.initializeSynchronous()
1051-
globalFuture = Future successful true
1052-
if (intp.reporter.hasErrors) {
1051+
globalFuture = Future.successful(true)
1052+
if (intp.reporter.hasErrors && (!isSbt || intp.reporter.hasReportableErrors)) {
10531053
echo("Interpreter encountered errors during initialization!")
10541054
null
10551055
} else {
@@ -1076,9 +1076,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
10761076
true
10771077
}
10781078
}
1079-
1080-
@deprecated("use `process` instead", "2.9.0")
1081-
def main(settings: Settings): Unit = process(settings) //used by sbt
10821079
}
10831080

10841081
object ILoop {

src/repl/scala/tools/nsc/interpreter/IMain.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
131131
catch AbstractOrMissingHandler()
132132
}
133133
private val logScope = scala.sys.props contains "scala.repl.scope"
134-
private def scopelog(msg: String) = if (logScope) Console.err.println(msg)
134+
private def scopelog(msg: => String) = if (logScope) Console.err.println(msg)
135135

136136
// argument is a thunk to execute after init is done
137137
def initialize(postInitSignal: => Unit) {
@@ -374,24 +374,25 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
374374
None
375375
}
376376

377-
private def updateReplScope(sym: Symbol, isDefined: Boolean) {
378-
def log(what: String) {
377+
private def updateReplScope(sym: Symbol, isDefined: Boolean): Unit = {
378+
def log(what: String) = scopelog {
379379
val mark = if (sym.isType) "t " else "v "
380380
val name = exitingTyper(sym.nameString)
381381
val info = cleanTypeAfterTyper(sym)
382382
val defn = sym defStringSeenAs info
383383

384-
scopelog(f"[$mark$what%6s] $name%-25s $defn%s")
384+
f"[$mark$what%6s] $name%-25s $defn%s"
385385
}
386-
if (ObjectClass isSubClass sym.owner) return
387-
// unlink previous
388-
replScope lookupAll sym.name foreach { sym =>
389-
log("unlink")
390-
replScope unlink sym
386+
if (!ObjectClass.isSubClass(sym.owner)) {
387+
// unlink previous
388+
replScope.lookupAll(sym.name) foreach { sym =>
389+
log("unlink")
390+
replScope unlink sym
391+
}
392+
val what = if (isDefined) "define" else "import"
393+
log(what)
394+
replScope enter sym
391395
}
392-
val what = if (isDefined) "define" else "import"
393-
log(what)
394-
replScope enter sym
395396
}
396397

397398
def recordRequest(req: Request) {

src/repl/scala/tools/nsc/interpreter/ReplReporter.scala

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,24 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
2929
finally _truncationOK = saved
3030
}
3131

32+
private[this] var silentErrors = 0
3233
override def warning(pos: Position, msg: String): Unit = withoutTruncating(super.warning(pos, msg))
33-
override def error(pos: Position, msg: String): Unit = withoutTruncating(super.error(pos, msg))
34+
override def error(pos: Position, msg: String): Unit = {
35+
val count0 = errorCount
36+
withoutTruncating(super.error(pos, msg))
37+
val count1 = errorCount
38+
if (count1 > count0 && intp.totalSilence)
39+
silentErrors += (count1 - count0)
40+
}
41+
private[interpreter] def reportableErrorCount = errorCount - silentErrors
42+
private[interpreter] def hasReportableErrors = reportableErrorCount > 0
43+
44+
override def reset(): Unit = {
45+
silentErrors = 0
46+
super.reset()
47+
}
3448

35-
import scala.io.AnsiColor.{ RED, YELLOW, RESET }
49+
import scala.io.AnsiColor.{RED, YELLOW, RESET}
3650

3751
def severityColor(severity: Severity): String = severity match {
3852
case ERROR => RED
@@ -50,7 +64,7 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
5064
}
5165

5266
// shift indentation for source text entered at prompt
53-
override def print(pos: Position, msg: String, severity: Severity) {
67+
override def print(pos: Position, msg: String, severity: Severity): Unit = {
5468
val adjusted =
5569
if (pos.source.file.name == "<console>")
5670
new OffsetPosition(pos.source, pos.offset.getOrElse(0)) {
@@ -61,7 +75,7 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
6175
super.print(adjusted, msg, severity)
6276
}
6377

64-
override def printMessage(msg: String) {
78+
override def printMessage(msg: String): Unit = {
6579
// Avoiding deadlock if the compiler starts logging before
6680
// the lazy val is complete.
6781
if (intp.isInitializeComplete) {
@@ -74,7 +88,7 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
7488
else Console.println("[init] " + msg)
7589
}
7690

77-
override def displayPrompt() = if (!intp.totalSilence) super.displayPrompt()
91+
override def displayPrompt(): Unit = if (!intp.totalSilence) super.displayPrompt()
7892

7993
override def rerunWithDetails(setting: reflect.internal.settings.MutableSettings#Setting, name: String) =
8094
s"; for details, enable `:setting $name' or `:replay $name'"

0 commit comments

Comments
 (0)