Skip to content
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
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ trait Reporting { this: Context =>

def reportWarning(warning: Warning): Unit =
if (!this.settings.silentWarnings.value) {
if (this.settings.XfatalWarnings.value) reporter.report(warning.toError)
if (this.settings.XfatalWarnings.value)
warning match {
case warning: ConditionalWarning if !warning.enablingOption.value =>
reporter.report(warning) // conditional warnings that are not enabled are not fatal
case _ =>
reporter.report(warning.toError)
}
else reporter.report(warning)
}

def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
if (this.settings.deprecation.value) reportWarning(new DeprecationWarning(msg, pos))
reportWarning(new DeprecationWarning(msg, pos))

def migrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
reportWarning(new MigrationWarning(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 @@ -162,6 +162,7 @@ class CompilationTests extends ParallelTesting {
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes) +
compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes) +
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes) +
compileFile("tests/neg-custom-args/conditionalWarnings.scala", allowDeepSubtypes.and("-deprecation").and("-Xfatal-warnings")) +
compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings") +
compileFile("tests/neg-custom-args/i3627.scala", allowDeepSubtypes) +
compileFile("tests/neg-custom-args/matchtype-loop.scala", allowDeepSubtypes) +
Expand Down
14 changes: 14 additions & 0 deletions tests/neg-custom-args/conditionalWarnings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

// run with -deprecation -Xfatal-warnings
object Test {
@deprecated def foo = ???

implied for Conversion[String, Int] = _.length

foo // error

val x: Int = "abc"
// OK, since -feature warnings are not enabled.
// The program compiles with final line
// there were 1 feature warning(s); re-run with -feature for details
}