Skip to content
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

add -Wconf flag for configurable warnings, @nowarn annotation for local suppression #8373

Merged
merged 9 commits into from Mar 9, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -59,3 +59,4 @@ jitwatch.out
# metals
.metals
.bloop
project/metals.sbt
4 changes: 4 additions & 0 deletions build.sbt
Expand Up @@ -186,6 +186,10 @@ val mimaFilterSettings = Seq {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.VirtualFile.unsafeToByteArray"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.ZipArchive#Entry.unsafeToByteArray"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.NoAbstractFile.unsafeToByteArray"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.runtime.JavaUniverse#PerRunReporting.deprecationWarning"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.nowarn$"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.nowarn"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.runtime.Settings#*.clearSetByUser"),
),
}

Expand Down
4 changes: 3 additions & 1 deletion src/compiler/scala/reflect/macros/contexts/FrontEnds.scala
Expand Up @@ -14,6 +14,7 @@ package scala.reflect.macros
package contexts

import scala.reflect.macros.runtime.AbortMacroException
import scala.tools.nsc.Reporting.WarningCategory

trait FrontEnds {
self: Context =>
Expand All @@ -27,7 +28,8 @@ trait FrontEnds {

def hasErrors: Boolean = universe.reporter.hasErrors

def warning(pos: Position, msg: String): Unit = callsiteTyper.context.warning(pos, msg)
// TODO: add WarningCategory parameter in 2.14 (not binary compatible)
def warning(pos: Position, msg: String): Unit = callsiteTyper.context.warning(pos, msg, WarningCategory.Other)

def error(pos: Position, msg: String): Unit = callsiteTyper.context.error(pos, msg)

Expand Down
15 changes: 0 additions & 15 deletions src/compiler/scala/tools/nsc/CompilationUnits.scala
Expand Up @@ -142,21 +142,6 @@ trait CompilationUnits { global: Global =>
/** For sbt compatibility (https://github.com/scala/scala/pull/4588) */
val icode: LinkedHashSet[icodes.IClass] = new LinkedHashSet

@deprecated("Call global.reporter.echo directly instead.", "2.11.2")
final def echo(pos: Position, msg: String): Unit = reporter.echo(pos, msg)
@deprecated("Call global.reporter.error (or typer.context.error) directly instead.", "2.11.2")
final def error(pos: Position, msg: String): Unit = reporter.error(pos, msg)
@deprecated("Call global.reporter.warning (or typer.context.warning) directly instead.", "2.11.2")
final def warning(pos: Position, msg: String): Unit = reporter.warning(pos, msg)

@deprecated("Call global.currentRun.reporting.deprecationWarning directly instead.", "2.11.2")
final def deprecationWarning(pos: Position, msg: String, since: String): Unit = currentRun.reporting.deprecationWarning(pos, msg, since)
@deprecated("Call global.currentRun.reporting.uncheckedWarning directly instead.", "2.11.2")
final def uncheckedWarning(pos: Position, msg: String): Unit = currentRun.reporting.uncheckedWarning(pos, msg)

@deprecated("This method will be removed. It does nothing.", "2.11.2")
final def comment(pos: Position, msg: String): Unit = {}

/** Is this about a .java source file? */
val isJava: Boolean = source.isJava

Expand Down
29 changes: 17 additions & 12 deletions src/compiler/scala/tools/nsc/Global.scala
Expand Up @@ -24,6 +24,7 @@ import scala.reflect.ClassTag
import scala.reflect.internal.pickling.PickleBuffer
import scala.reflect.internal.util.{BatchSourceFile, FreshNameCreator, NoSourceFile, ScriptSourceFile, SourceFile}
import scala.reflect.internal.{Reporter => InternalReporter}
import scala.tools.nsc.Reporting.WarningCategory
import scala.tools.nsc.ast.parser._
import scala.tools.nsc.ast.{TreeGen => AstTreeGen, _}
import scala.tools.nsc.backend.jvm.{BackendStats, GenBCode}
Expand Down Expand Up @@ -294,7 +295,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
@inline final def devWarning(pos: Position, msg: => String): Unit = {
def pos_s = if (pos eq NoPosition) "" else s" [@ $pos]"
if (isDeveloper)
warning(pos, "!!! " + msg)
runReporting.warning(pos, "!!! " + msg, WarningCategory.OtherDebug, site = "")
else
log(s"!!!$pos_s $msg") // such warnings always at least logged
}
Expand Down Expand Up @@ -884,7 +885,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
case Some(oldEntry) =>
Some(oldEntry -> ClassPathFactory.newClassPath(dir, settings, closeableRegistry))
case None =>
error(s"Error adding entry to classpath. During invalidation, no entry named $path in classpath $classPath")
globalError(s"Error adding entry to classpath. During invalidation, no entry named $path in classpath $classPath")
None
}
}
Expand Down Expand Up @@ -992,10 +993,11 @@ class Global(var currentSettings: Settings, reporter0: Reporter)

/** The currently active run
*/
def currentRun: Run = curRun
def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit
def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile
def currentFreshNameCreator = if (curFreshNameCreator == null) currentUnit.fresh else curFreshNameCreator
def currentRun: Run = curRun
def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit
def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile
def runReporting: PerRunReporting = currentRun.reporting
def currentFreshNameCreator = if (curFreshNameCreator == null) currentUnit.fresh else curFreshNameCreator
private[this] var curFreshNameCreator: FreshNameCreator = null
private[scala] def currentFreshNameCreator_=(fresh: FreshNameCreator): Unit = curFreshNameCreator = fresh

Expand Down Expand Up @@ -1139,9 +1141,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
val isScala300: Boolean = settings.isScala300

// used in sbt
def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings.map{case (pos, (msg, since)) => (pos, msg)}
def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings
// used in sbt
def deprecationWarnings: List[(Position, String)] = reporting.deprecationWarnings.map{case (pos, (msg, since)) => (pos, msg)}
def deprecationWarnings: List[(Position, String)] = reporting.deprecationWarnings

private class SyncedCompilationBuffer { self =>
private val underlying = new mutable.ArrayBuffer[CompilationUnit]
Expand Down Expand Up @@ -1249,8 +1251,8 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
val count =
if (including) first.iterator.count(tester.containsPhase(_))
else phaseDescriptors.count(pd => tester.contains(pd.phaseName))
if (count == 0) warning(s"'$p' specifies no phase")
if (count > 1 && !isSpecial(p)) warning(s"'$p' selects $count phases")
if (count == 0) runReporting.warning(NoPosition, s"'$p' specifies no phase", WarningCategory.Other, site = "")
if (count > 1 && !isSpecial(p)) runReporting.warning(NoPosition, s"'$p' selects $count phases", WarningCategory.Other, site = "")
if (!including && isSpecial(p)) globalError(s"-Yskip and -Ystop values must name phases: '$p'")
tester.clear()
}
Expand Down Expand Up @@ -1360,9 +1362,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
private def warnDeprecatedAndConflictingSettings(): Unit = {
// issue warnings for any usage of deprecated settings
settings.userSetSettings filter (_.isDeprecated) foreach { s =>
currentRun.reporting.deprecationWarning(NoPosition, s.name + " is deprecated: " + s.deprecationMessage.get, "")
runReporting.deprecationWarning(NoPosition, s.name + " is deprecated: " + s.deprecationMessage.get, "", "", "")
}
settings.conflictWarning.foreach(reporter.warning(NoPosition, _))
settings.conflictWarning.foreach(runReporting.warning(NoPosition, _, WarningCategory.Other, site = ""))
}

/* An iterator returning all the units being compiled in this run */
Expand Down Expand Up @@ -1542,6 +1544,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
if (settings.YstatisticsEnabled && settings.Ystatistics.contains(phase.name))
printStatisticsFor(phase)

if (!globalPhase.hasNext || reporter.hasErrors)
runReporting.warnUnusedSuppressions()
lrytz marked this conversation as resolved.
Show resolved Hide resolved

advancePhase()
}
profiler.finished()
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/scala/tools/nsc/GlobalSymbolLoaders.scala
Expand Up @@ -14,6 +14,8 @@ package scala
package tools
package nsc

import scala.tools.nsc.Reporting.WarningCategory

/**
* Symbol loaders implementation that wires dependencies using Global.
*/
Expand All @@ -34,4 +36,7 @@ abstract class GlobalSymbolLoaders extends symtab.SymbolLoaders {

protected def compileLate(srcfile: io.AbstractFile): Unit =
currentRun.compileLate(srcfile)

def warning(pos: Position, msg: String, category: WarningCategory, site: String): Unit =
runReporting.warning(pos, msg, category, site)
}
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/PhaseAssembly.scala
Expand Up @@ -13,6 +13,7 @@
package scala.tools.nsc

import scala.collection.mutable
import scala.tools.nsc.Reporting.WarningCategory

/** Converts an unordered morass of components into an order that
* satisfies their mutual constraints.
Expand Down Expand Up @@ -202,7 +203,7 @@ trait PhaseAssembly {
edges -= edge
edge.frm.after -= edge
if (edge.frm.phaseobj exists (lsc => !lsc.head.internal))
warning(msg)
runReporting.warning(NoPosition, msg, WarningCategory.Other, site = "")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/PipelineMain.scala
Expand Up @@ -31,6 +31,7 @@ import scala.math.Ordering.Double.TotalOrdering
import scala.reflect.internal.util.{BatchSourceFile, FakePos, NoPosition, Position}
import scala.reflect.io.PlainNioFile
import scala.tools.nsc.PipelineMain.{OutlineTypePipeline, Pipeline, Traditional}
import scala.tools.nsc.Reporting.WarningCategory
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.reporters.{ConsoleReporter, Reporter}
import scala.tools.nsc.util.ClassPath
Expand Down Expand Up @@ -564,7 +565,7 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe
}
diagnostic.getKind match {
case Kind.ERROR => reporter.error(position, msg)
case Kind.WARNING | Kind.MANDATORY_WARNING => reporter.warning(position, msg)
case Kind.WARNING | Kind.MANDATORY_WARNING => Task.this.compiler.runReporting.warning(position, msg, WarningCategory.JavaSource, site = "")
case Kind.NOTE | Kind.OTHER => reporter.echo(position, msg)
}
}
Expand Down