Skip to content

Commit 954afd4

Browse files
authored
Merge pull request #2341 from teigen/xfatal-warnings
support for -Xfatal-warnings
2 parents a37d233 + 16171a6 commit 954afd4

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ScalaSettings extends Settings.SettingGroup {
5757
val mainClass = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d <jar>)", "")
5858
val XnoValueClasses = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
5959
val XreplLineWidth = IntSetting("-Xrepl-line-width", "Maximial number of columns per line for REPL output", 390)
60+
val XfatalWarnings = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
6061

6162
/** -Y "Private" settings */
6263
val overrideVars = BooleanSetting("-Yoverride-vars", "Allow vars to be overridden.")

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,21 @@ trait Reporting { this: Context =>
3737
def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
3838
reporter.report(new Info(msg, pos))
3939

40+
def reportWarning(warning:Warning):Unit =
41+
if(this.settings.XfatalWarnings.value) error(warning.contained, warning.pos)
42+
else reporter.report(warning)
43+
4044
def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
41-
reporter.report(new DeprecationWarning(msg, pos))
45+
reportWarning(new DeprecationWarning(msg, pos))
4246

4347
def migrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
44-
reporter.report(new MigrationWarning(msg, pos))
48+
reportWarning(new MigrationWarning(msg, pos))
4549

4650
def uncheckedWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
47-
reporter.report(new UncheckedWarning(msg, pos))
51+
reportWarning(new UncheckedWarning(msg, pos))
4852

4953
def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
50-
reporter.report(new FeatureWarning(msg, pos))
54+
reportWarning(new FeatureWarning(msg, pos))
5155

5256
def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean,
5357
featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = {
@@ -69,17 +73,15 @@ trait Reporting { this: Context =>
6973

7074
val msg = s"$featureDescription $req be enabled\nby making the implicit value $fqname visible.$explain"
7175
if (required) error(msg, pos)
72-
else reporter.report(new FeatureWarning(msg, pos))
76+
else reportWarning(new FeatureWarning(msg, pos))
7377
}
7478

7579
def warning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
76-
reporter.report(new Warning(msg, pos))
80+
reportWarning(new Warning(msg, pos))
7781

7882
def strictWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
7983
if (this.settings.strict.value) error(msg, pos)
80-
else reporter.report {
81-
new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos)
82-
}
84+
else reportWarning(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos))
8385

8486
def error(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
8587
reporter.report(new Error(msg, pos))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class CompilationTests extends ParallelTesting {
145145
compileFile("../tests/neg/customArgs/noimports.scala", defaultOptions.and("-Yno-imports")) +
146146
compileFile("../tests/neg/customArgs/noimports2.scala", defaultOptions.and("-Yno-imports")) +
147147
compileFile("../tests/neg/customArgs/overloadsOnAbstractTypes.scala", allowDoubleBindings) +
148+
compileFile("../tests/neg/customArgs/xfatalWarnings.scala", defaultOptions.and("-Xfatal-warnings")) +
148149
compileFile("../tests/neg/tailcall/t1672b.scala", defaultOptions) +
149150
compileFile("../tests/neg/tailcall/t3275.scala", defaultOptions) +
150151
compileFile("../tests/neg/tailcall/t6574.scala", defaultOptions) +
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object xfatalWarnings {
2+
val opt:Option[String] = Some("test")
3+
4+
opt match { // error when running with -Xfatal-warnings
5+
case None =>
6+
}
7+
}

0 commit comments

Comments
 (0)