Skip to content

Commit e7ed71b

Browse files
authored
Merge pull request scala#5667 from som-snytt/issue/maxerrs
SI-9729 -Xmaxerrs to limit messages
2 parents fff1732 + 633e6ef commit e7ed71b

File tree

9 files changed

+109
-8
lines changed

9 files changed

+109
-8
lines changed

src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
2020
var shortname: Boolean = false
2121

2222
/** maximal number of error messages to be printed */
23+
@deprecated("configured by settings.maxerrs", since="2.12.2")
2324
final val ERROR_LIMIT = 100
2425

2526
private def label(severity: Severity): String = severity match {
@@ -63,9 +64,13 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
6364
if ( ERROR.count > 0) printMessage(getCountString(ERROR ) + " found")
6465
}
6566

66-
def display(pos: Position, msg: String, severity: Severity) {
67-
if (severity != ERROR || severity.count <= ERROR_LIMIT)
68-
print(pos, msg, severity)
67+
def display(pos: Position, msg: String, severity: Severity): Unit = {
68+
val ok = severity match {
69+
case ERROR => ERROR.count <= settings.maxerrs.value
70+
case WARNING => WARNING.count <= settings.maxwarns.value
71+
case _ => true
72+
}
73+
if (ok) print(pos, msg, severity)
6974
}
7075

7176
def displayPrompt(): Unit = {

src/compiler/scala/tools/nsc/settings/MutableSettings.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ class MutableSettings(val errorFn: String => Unit)
416416
// Helper to generate a textual explanation of valid inputs
417417
private def getValidText: String = (min, max) match {
418418
case (IntMin, IntMax) => "can be any integer"
419-
case (IntMin, x) => "must be less than or equal to "+x
420-
case (x, IntMax) => "must be greater than or equal to "+x
421-
case _ => "must be between %d and %d".format(min, max)
419+
case (IntMin, x) => f"must be less than or equal to $x%d"
420+
case (x, IntMax) => f"must be greater than or equal to $x%d"
421+
case _ => f"must be between $min%d and $max%d"
422422
}
423423

424424
// Ensure that the default value is actually valid
@@ -431,7 +431,7 @@ class MutableSettings(val errorFn: String => Unit)
431431
}
432432
}
433433

434-
def errorMsg() = errorFn("invalid setting for -"+name+" "+getValidText)
434+
def errorMsg() = errorFn(s"invalid setting for $name $getValidText")
435435

436436
def tryToSet(args: List[String]) =
437437
if (args.isEmpty) errorAndValue("missing argument", None)
@@ -444,7 +444,7 @@ class MutableSettings(val errorFn: String => Unit)
444444
if (value == default) Nil
445445
else List(name, value.toString)
446446

447-
withHelpSyntax(name + " <n>")
447+
withHelpSyntax(s"$name <n>")
448448
}
449449

450450
/** A setting represented by a boolean flag (false, unless set) */

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ trait ScalaSettings extends AbsScalaSettings
107107
val logFreeTerms = BooleanSetting ("-Xlog-free-terms", "Print a message when reification creates a free term.")
108108
val logFreeTypes = BooleanSetting ("-Xlog-free-types", "Print a message when reification resorts to generating a free type.")
109109
val maxClassfileName = IntSetting ("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, Some((72, 255)), _ => None)
110+
val maxerrs = IntSetting ("-Xmaxerrs", "Maximum errors to print", 100, None, _ => None)
111+
val maxwarns = IntSetting ("-Xmaxwarns", "Maximum warnings to print", 100, None, _ => None)
110112
val Xmigration = ScalaVersionSetting ("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", initial = NoScalaVersion, default = Some(AnyScalaVersion))
111113
val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.")
112114
val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.")

test/files/neg/maxerrs.check

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
maxerrs.scala:22: error: type mismatch;
2+
found : String("")
3+
required: Int
4+
def F = f("")
5+
^
6+
maxerrs.scala:24: error: type mismatch;
7+
found : String("")
8+
required: Int
9+
def g = f("")
10+
^
11+
maxerrs.scala:26: error: type mismatch;
12+
found : String("")
13+
required: Int
14+
def h = f("")
15+
^
16+
5 errors found

test/files/neg/maxerrs.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xmaxerrs 3 -Xfatal-warnings -deprecation

test/files/neg/maxerrs.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
object X {
3+
@deprecated("just to annoy people", since="forever")
4+
def x = 42
5+
6+
def f(i: Int) = i
7+
}
8+
9+
trait T {
10+
import X._
11+
12+
def a = x
13+
14+
def b = x
15+
16+
def c = x
17+
18+
def d = x
19+
20+
def e = x
21+
22+
def F = f("")
23+
24+
def g = f("")
25+
26+
def h = f("")
27+
28+
def i = f("")
29+
30+
def j = f("")
31+
}
32+

test/files/neg/maxwarns.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
maxwarns.scala:12: warning: method x in object X is deprecated (since forever): just to annoy people
2+
def a = x
3+
^
4+
maxwarns.scala:14: warning: method x in object X is deprecated (since forever): just to annoy people
5+
def b = x
6+
^
7+
maxwarns.scala:16: warning: method x in object X is deprecated (since forever): just to annoy people
8+
def c = x
9+
^
10+
error: No warnings can be incurred under -Xfatal-warnings.
11+
5 warnings found
12+
one error found

test/files/neg/maxwarns.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xmaxwarns 3 -Xfatal-warnings -deprecation

test/files/neg/maxwarns.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
object X {
3+
@deprecated("just to annoy people", since="forever")
4+
def x = 42
5+
6+
def f(i: String) = i
7+
}
8+
9+
trait T {
10+
import X._
11+
12+
def a = x
13+
14+
def b = x
15+
16+
def c = x
17+
18+
def d = x
19+
20+
def e = x
21+
22+
def F = f("")
23+
24+
def g = f("")
25+
26+
def h = f("")
27+
28+
def i = f("")
29+
30+
def j = f("")
31+
}
32+

0 commit comments

Comments
 (0)