diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 941434dd5ff3..c8d4f7d79485 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -57,6 +57,7 @@ class ScalaSettings extends Settings.SettingGroup { val mainClass = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d )", "") val XnoValueClasses = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.") val XreplLineWidth = IntSetting("-Xrepl-line-width", "Maximial number of columns per line for REPL output", 390) + val XfatalWarnings = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.") /** -Y "Private" settings */ val overrideVars = BooleanSetting("-Yoverride-vars", "Allow vars to be overridden.") diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index 77ea1884dbcf..f3409bcd9d2d 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -37,17 +37,21 @@ trait Reporting { this: Context => def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = reporter.report(new Info(msg, pos)) + def reportWarning(warning:Warning):Unit = + if(this.settings.XfatalWarnings.value) error(warning.contained, warning.pos) + else reporter.report(warning) + def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new DeprecationWarning(msg, pos)) + reportWarning(new DeprecationWarning(msg, pos)) def migrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new MigrationWarning(msg, pos)) + reportWarning(new MigrationWarning(msg, pos)) def uncheckedWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new UncheckedWarning(msg, pos)) + reportWarning(new UncheckedWarning(msg, pos)) def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new FeatureWarning(msg, pos)) + reportWarning(new FeatureWarning(msg, pos)) def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean, featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = { @@ -69,17 +73,15 @@ trait Reporting { this: Context => val msg = s"$featureDescription $req be enabled\nby making the implicit value $fqname visible.$explain" if (required) error(msg, pos) - else reporter.report(new FeatureWarning(msg, pos)) + else reportWarning(new FeatureWarning(msg, pos)) } def warning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new Warning(msg, pos)) + reportWarning(new Warning(msg, pos)) def strictWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = if (this.settings.strict.value) error(msg, pos) - else reporter.report { - new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos) - } + else reportWarning(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos)) def error(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = reporter.report(new Error(msg, pos)) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 91a453494760..df7a1141cec9 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -145,6 +145,7 @@ class CompilationTests extends ParallelTesting { compileFile("../tests/neg/customArgs/noimports.scala", defaultOptions.and("-Yno-imports")) + compileFile("../tests/neg/customArgs/noimports2.scala", defaultOptions.and("-Yno-imports")) + compileFile("../tests/neg/customArgs/overloadsOnAbstractTypes.scala", allowDoubleBindings) + + compileFile("../tests/neg/customArgs/xfatalWarnings.scala", defaultOptions.and("-Xfatal-warnings")) + compileFile("../tests/neg/tailcall/t1672b.scala", defaultOptions) + compileFile("../tests/neg/tailcall/t3275.scala", defaultOptions) + compileFile("../tests/neg/tailcall/t6574.scala", defaultOptions) + diff --git a/tests/neg/customArgs/xfatalWarnings.scala b/tests/neg/customArgs/xfatalWarnings.scala new file mode 100644 index 000000000000..86ca7ed8f4dc --- /dev/null +++ b/tests/neg/customArgs/xfatalWarnings.scala @@ -0,0 +1,7 @@ +object xfatalWarnings { + val opt:Option[String] = Some("test") + + opt match { // error when running with -Xfatal-warnings + case None => + } +} \ No newline at end of file