Skip to content

Commit feafd80

Browse files
authored
Merge pull request #2365 from markus1189/nowarn
Add -nowarn option to silence warnings
2 parents e67ff61 + 1b4e582 commit feafd80

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ScalaSettings extends Settings.SettingGroup {
4141
val strict = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.")
4242
val language = MultiStringSetting("-language", "feature", "Enable one or more language features.")
4343
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
44+
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
4445

4546
/** -X "Advanced" settings
4647
*/

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ trait Reporting { this: Context =>
3838
reporter.report(new Info(msg, pos))
3939

4040
def reportWarning(warning: Warning): Unit =
41-
if (this.settings.XfatalWarnings.value) reporter.report(warning.toError)
42-
else reporter.report(warning)
41+
if (!this.settings.silentWarnings.value) {
42+
if (this.settings.XfatalWarnings.value) reporter.report(warning.toError)
43+
else reporter.report(warning)
44+
}
4345

4446
def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
4547
reportWarning(new DeprecationWarning(msg, pos))

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ class CompilationTests extends ParallelTesting {
7272
scala2Mode
7373
) +
7474
compileFilesInDir("../tests/new", defaultOptions) +
75-
compileFilesInDir("../tests/pos-scala2", scala2Mode)
76-
compileFilesInDir("../tests/pos", defaultOptions)
75+
compileFilesInDir("../tests/pos-scala2", scala2Mode) +
76+
compileFilesInDir("../tests/pos", defaultOptions) +
77+
compileFile(
78+
// succeeds despite -Xfatal-warnings because of -nowarn
79+
"../tests/neg/customArgs/xfatalWarnings.scala",
80+
defaultOptions.and("-nowarn", "-Xfatal-warnings")
81+
)
7782
}.checkCompile()
7883

7984
@Test def posTwice: Unit = {
@@ -239,7 +244,7 @@ class CompilationTests extends ParallelTesting {
239244
}.map(_.checkCompile()).foreach(_.delete())
240245
}
241246

242-
@Test def bytecodeIdemporency: Unit = {
247+
@Test def bytecodeIdempotency: Unit = {
243248
var failed = 0
244249
var total = 0
245250
val blacklisted = Set(

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ trait ErrorMessagesTest extends DottyTest {
1616
private def freshReporter(ctx: Context) =
1717
ctx.fresh.setReporter(new CapturingReporter)
1818

19-
2019
class Report(messages: List[Message], ictx: Context) {
2120
def expect(f: (Context, List[Message]) => Unit): Unit = {
2221
f(ictx, messages)

tests/pos-special/nowarn.scala

Whitespace-only changes.

0 commit comments

Comments
 (0)