Skip to content

support for -Xfatal-warnings #2341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jar>)", "")
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.")
Expand Down
20 changes: 11 additions & 9 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/customArgs/xfatalWarnings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object xfatalWarnings {
val opt:Option[String] = Some("test")

opt match { // error when running with -Xfatal-warnings
case None =>
}
}