Skip to content

Commit a20345d

Browse files
authored
Merge pull request scala#8373 from lrytz/confwarn
add -Wconf flag for configurable warnings, @nowarn annotation for local suppression
2 parents 7da8ce2 + 251e4a5 commit a20345d

File tree

149 files changed

+2331
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+2331
-757
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ jitwatch.out
5959
# metals
6060
.metals
6161
.bloop
62+
project/metals.sbt

build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ val mimaFilterSettings = Seq {
186186
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.VirtualFile.unsafeToByteArray"),
187187
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.ZipArchive#Entry.unsafeToByteArray"),
188188
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.io.NoAbstractFile.unsafeToByteArray"),
189+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.runtime.JavaUniverse#PerRunReporting.deprecationWarning"),
190+
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.nowarn$"),
191+
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.nowarn"),
192+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.runtime.Settings#*.clearSetByUser"),
189193
),
190194
}
191195

src/compiler/scala/reflect/macros/contexts/FrontEnds.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package scala.reflect.macros
1414
package contexts
1515

1616
import scala.reflect.macros.runtime.AbortMacroException
17+
import scala.tools.nsc.Reporting.WarningCategory
1718

1819
trait FrontEnds {
1920
self: Context =>
@@ -27,7 +28,8 @@ trait FrontEnds {
2728

2829
def hasErrors: Boolean = universe.reporter.hasErrors
2930

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

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

src/compiler/scala/tools/nsc/CompilationUnits.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,6 @@ trait CompilationUnits { global: Global =>
142142
/** For sbt compatibility (https://github.com/scala/scala/pull/4588) */
143143
val icode: LinkedHashSet[icodes.IClass] = new LinkedHashSet
144144

145-
@deprecated("Call global.reporter.echo directly instead.", "2.11.2")
146-
final def echo(pos: Position, msg: String): Unit = reporter.echo(pos, msg)
147-
@deprecated("Call global.reporter.error (or typer.context.error) directly instead.", "2.11.2")
148-
final def error(pos: Position, msg: String): Unit = reporter.error(pos, msg)
149-
@deprecated("Call global.reporter.warning (or typer.context.warning) directly instead.", "2.11.2")
150-
final def warning(pos: Position, msg: String): Unit = reporter.warning(pos, msg)
151-
152-
@deprecated("Call global.currentRun.reporting.deprecationWarning directly instead.", "2.11.2")
153-
final def deprecationWarning(pos: Position, msg: String, since: String): Unit = currentRun.reporting.deprecationWarning(pos, msg, since)
154-
@deprecated("Call global.currentRun.reporting.uncheckedWarning directly instead.", "2.11.2")
155-
final def uncheckedWarning(pos: Position, msg: String): Unit = currentRun.reporting.uncheckedWarning(pos, msg)
156-
157-
@deprecated("This method will be removed. It does nothing.", "2.11.2")
158-
final def comment(pos: Position, msg: String): Unit = {}
159-
160145
/** Is this about a .java source file? */
161146
val isJava: Boolean = source.isJava
162147

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import scala.reflect.ClassTag
2424
import scala.reflect.internal.pickling.PickleBuffer
2525
import scala.reflect.internal.util.{BatchSourceFile, FreshNameCreator, NoSourceFile, ScriptSourceFile, SourceFile}
2626
import scala.reflect.internal.{Reporter => InternalReporter}
27+
import scala.tools.nsc.Reporting.WarningCategory
2728
import scala.tools.nsc.ast.parser._
2829
import scala.tools.nsc.ast.{TreeGen => AstTreeGen, _}
2930
import scala.tools.nsc.backend.jvm.{BackendStats, GenBCode}
@@ -294,7 +295,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
294295
@inline final def devWarning(pos: Position, msg: => String): Unit = {
295296
def pos_s = if (pos eq NoPosition) "" else s" [@ $pos]"
296297
if (isDeveloper)
297-
warning(pos, "!!! " + msg)
298+
runReporting.warning(pos, "!!! " + msg, WarningCategory.OtherDebug, site = "")
298299
else
299300
log(s"!!!$pos_s $msg") // such warnings always at least logged
300301
}
@@ -884,7 +885,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
884885
case Some(oldEntry) =>
885886
Some(oldEntry -> ClassPathFactory.newClassPath(dir, settings, closeableRegistry))
886887
case None =>
887-
error(s"Error adding entry to classpath. During invalidation, no entry named $path in classpath $classPath")
888+
globalError(s"Error adding entry to classpath. During invalidation, no entry named $path in classpath $classPath")
888889
None
889890
}
890891
}
@@ -992,10 +993,11 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
992993

993994
/** The currently active run
994995
*/
995-
def currentRun: Run = curRun
996-
def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit
997-
def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile
998-
def currentFreshNameCreator = if (curFreshNameCreator == null) currentUnit.fresh else curFreshNameCreator
996+
def currentRun: Run = curRun
997+
def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit
998+
def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile
999+
def runReporting: PerRunReporting = currentRun.reporting
1000+
def currentFreshNameCreator = if (curFreshNameCreator == null) currentUnit.fresh else curFreshNameCreator
9991001
private[this] var curFreshNameCreator: FreshNameCreator = null
10001002
private[scala] def currentFreshNameCreator_=(fresh: FreshNameCreator): Unit = curFreshNameCreator = fresh
10011003

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

11411143
// used in sbt
1142-
def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings.map{case (pos, (msg, since)) => (pos, msg)}
1144+
def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings
11431145
// used in sbt
1144-
def deprecationWarnings: List[(Position, String)] = reporting.deprecationWarnings.map{case (pos, (msg, since)) => (pos, msg)}
1146+
def deprecationWarnings: List[(Position, String)] = reporting.deprecationWarnings
11451147

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

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

1547+
if (!globalPhase.hasNext || reporter.hasErrors)
1548+
runReporting.warnUnusedSuppressions()
1549+
15451550
advancePhase()
15461551
}
15471552
profiler.finished()

src/compiler/scala/tools/nsc/GlobalSymbolLoaders.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ package scala
1414
package tools
1515
package nsc
1616

17+
import scala.tools.nsc.Reporting.WarningCategory
18+
1719
/**
1820
* Symbol loaders implementation that wires dependencies using Global.
1921
*/
@@ -34,4 +36,7 @@ abstract class GlobalSymbolLoaders extends symtab.SymbolLoaders {
3436

3537
protected def compileLate(srcfile: io.AbstractFile): Unit =
3638
currentRun.compileLate(srcfile)
39+
40+
def warning(pos: Position, msg: String, category: WarningCategory, site: String): Unit =
41+
runReporting.warning(pos, msg, category, site)
3742
}

src/compiler/scala/tools/nsc/PhaseAssembly.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package scala.tools.nsc
1414

1515
import scala.collection.mutable
16+
import scala.tools.nsc.Reporting.WarningCategory
1617

1718
/** Converts an unordered morass of components into an order that
1819
* satisfies their mutual constraints.
@@ -202,7 +203,7 @@ trait PhaseAssembly {
202203
edges -= edge
203204
edge.frm.after -= edge
204205
if (edge.frm.phaseobj exists (lsc => !lsc.head.internal))
205-
warning(msg)
206+
runReporting.warning(NoPosition, msg, WarningCategory.Other, site = "")
206207
}
207208
}
208209
}

src/compiler/scala/tools/nsc/PipelineMain.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import scala.math.Ordering.Double.TotalOrdering
3131
import scala.reflect.internal.util.{BatchSourceFile, FakePos, NoPosition, Position}
3232
import scala.reflect.io.PlainNioFile
3333
import scala.tools.nsc.PipelineMain.{OutlineTypePipeline, Pipeline, Traditional}
34+
import scala.tools.nsc.Reporting.WarningCategory
3435
import scala.tools.nsc.io.AbstractFile
3536
import scala.tools.nsc.reporters.{ConsoleReporter, Reporter}
3637
import scala.tools.nsc.util.ClassPath
@@ -564,7 +565,7 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe
564565
}
565566
diagnostic.getKind match {
566567
case Kind.ERROR => reporter.error(position, msg)
567-
case Kind.WARNING | Kind.MANDATORY_WARNING => reporter.warning(position, msg)
568+
case Kind.WARNING | Kind.MANDATORY_WARNING => Task.this.compiler.runReporting.warning(position, msg, WarningCategory.JavaSource, site = "")
568569
case Kind.NOTE | Kind.OTHER => reporter.echo(position, msg)
569570
}
570571
}

0 commit comments

Comments
 (0)