Skip to content

Commit

Permalink
Adjust deprecation config after Wconf
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Apr 11, 2024
1 parent 18b61a9 commit 820ad16
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 88 deletions.
17 changes: 14 additions & 3 deletions src/compiler/scala/tools/nsc/Reporting.scala
Expand Up @@ -53,11 +53,22 @@ trait Reporting extends internal.Reporting { self: ast.Positions with Compilatio
globalError(s"Failed to parse `-Wconf` configuration: ${settings.Wconf.value}\n${msgs.mkString("\n")}$multiHelp")
WConf(Nil)
case Right(conf) =>
// configure cat=scala3-migration if it isn't yet
// configure cat=scala3-migration:e and if -deprecation cat=deprecation:w or s (instead of default ws)
val adjusted =
if (settings.deprecation.isSetByUser) {
val (user, defaults) = conf.filters.splitAt(conf.filters.length - settings.WconfDefault.length)
val Deprecation = MessageFilter.Category(WarningCategory.Deprecation)
val action = if (settings.deprecation.value) Action.Warning else Action.Silent
val fixed = defaults.map {
case (cat @ Deprecation :: Nil, Action.WarningSummary) => cat -> action
case other => other
}
conf.copy(filters = user ::: fixed)
}
else conf
val Migration = MessageFilter.Category(WarningCategory.Scala3Migration)
val boost = (settings.isScala3: @nowarn) && !conf.filters.exists(_._1.exists(_ == Migration))
if (boost) conf.copy(filters = conf.filters :+ (Migration :: Nil, Action.Error))
else conf
if (boost) adjusted.copy(filters = adjusted.filters :+ (Migration :: Nil, Action.Error)) else adjusted
}

private lazy val quickfixFilters = {
Expand Down
23 changes: 23 additions & 0 deletions src/compiler/scala/tools/nsc/settings/MutableSettings.scala
Expand Up @@ -355,6 +355,8 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
private[this] var _deprecationMessage: Option[String] = None
override def deprecationMessage = _deprecationMessage
def withDeprecationMessage(msg: String): this.type = { _deprecationMessage = Some(msg) ; this }

def reset(): Unit
}

/** A setting represented by an integer. */
Expand Down Expand Up @@ -419,6 +421,8 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
else List(name, value.toString)

withHelpSyntax(s"$name <n>")

override def reset() = v = default
}

/** A setting that is a boolean flag, with default as specified. */
Expand All @@ -443,6 +447,10 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
} else errorAndValue(s"'$x' is not a valid choice for '$name'", None)
case _ => errorAndValue(s"'$name' accepts only one boolean value", None)
}
override def reset() = {
v = default
setByUser = false
}
}

/** A special setting for accumulating arguments like -Dfoo=bar. */
Expand All @@ -464,6 +472,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
def tryToSetColon(args: List[String]): Option[ResultOfTryToSet] = errorAndValue(s"bad argument for $name", None)
override def respondsTo(token: String) = token startsWith prefix
def unparse: List[String] = value
override def reset() = v = Nil
}

/** A setting represented by a string, (`default` unless set) */
Expand Down Expand Up @@ -495,6 +504,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
override def isHelping: Boolean = sawHelp

override def help = helpText.get
override def reset() = v = default
}

/** A setting represented by a Scala version.
Expand Down Expand Up @@ -536,6 +546,8 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
override def help = helpText.get

withHelpSyntax(s"${name}:<${arg}>")

override def reset() = v = initial
}

class PathSetting private[nsc](
Expand All @@ -555,6 +567,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
super.value,
appendPath.value
)
override def reset() = ()
}

/** Set the output directory for all sources. */
Expand Down Expand Up @@ -794,6 +807,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
}
def unparse: List[String] = value.toList.map(s => s"$name:$s")
def contains(s: String) = domain.values.find(_.toString == s).exists(value.contains)
override def reset() = clear()
}

/** A setting that accumulates all strings supplied to it,
Expand Down Expand Up @@ -838,6 +852,11 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
override def isHelping: Boolean = sawHelp

override def help = helpText.get

override def reset() = {
v = default
setByUser = false
}
}

/** A setting represented by a string in a given set of `choices`,
Expand Down Expand Up @@ -892,6 +911,8 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
override def tryToSetFromPropertyValue(s: String) = tryToSetColon(s::Nil) // used from ide

withHelpSyntax(name + ":<" + helpArg + ">")

override def reset() = v = default
}

private def mkPhasesHelp(descr: String, default: String) = {
Expand Down Expand Up @@ -972,6 +993,8 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
if (default == "") name + ":<phases>"
else name + "[:phases]"
)

override def reset() = clear()
}

/** Internal use - syntax enhancements. */
Expand Down
Expand Up @@ -36,10 +36,7 @@ trait StandardScalaSettings { _: MutableSettings =>
/** Other settings.
*/
val dependencyfile = StringSetting ("-dependencyfile", "file", "Set dependency tracking file.", ".scala_dependencies") withAbbreviation "--dependency-file"
val deprecation = BooleanSetting ("-deprecation", "Emit warning and location for usages of deprecated APIs. See also -Wconf.") withAbbreviation "--deprecation" withPostSetHook { s =>
if (s.value) Wconf.tryToSet(List(s"cat=deprecation:w"))
else Wconf.tryToSet(List(s"cat=deprecation:s"))
}
val deprecation = BooleanSetting ("-deprecation", "Emit warning and location for usages of deprecated APIs. See also -Wconf.").withAbbreviation("--deprecation")
val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files.", Properties.sourceEncoding) withAbbreviation "--encoding"
val explaintypes = BooleanSetting ("-explaintypes", "Explain type errors in more detail.") withAbbreviation "--explain-types"
val feature = BooleanSetting ("-feature", "Emit warning and location for usages of features that should be imported explicitly. See also -Wconf.") withAbbreviation "--feature" withPostSetHook { s =>
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/settings/Warnings.scala
Expand Up @@ -27,7 +27,7 @@ trait Warnings {
// Warning semantics.
val fatalWarnings = BooleanSetting("-Werror", "Fail the compilation if there are any warnings.") withAbbreviation "-Xfatal-warnings"

private val WconfDefault = List("cat=deprecation:ws", "cat=feature:ws", "cat=optimizer:ws")
val WconfDefault = List("cat=deprecation:ws", "cat=feature:ws", "cat=optimizer:ws")
// Note: user-defined settings are added on the right, but the value is reversed before
// it's parsed, so that later defined settings take precedence.
val Wconf = MultiStringSetting(
Expand Down
6 changes: 6 additions & 0 deletions test/files/neg/t12984.check
@@ -0,0 +1,6 @@
t12984.scala:12: warning: class D is deprecated (since 2.0): Will be phased out eventually someday.
def d = new D
^
error: No warnings can be incurred under -Werror.
1 warning
1 error
13 changes: 13 additions & 0 deletions test/files/neg/t12984.scala
@@ -0,0 +1,13 @@

//> using options -deprecation -Wconf:cat=deprecation&origin=C:s -Werror -Xlint

@deprecated("Just say no.", since="1.0")
class C

@deprecated("Will be phased out eventually someday.", since="2.0")
class D

trait Test {
def c = new C
def d = new D
}
3 changes: 1 addition & 2 deletions test/files/pos/t8410.scala
@@ -1,5 +1,4 @@
// scalac: -opt:inline:** -Wopt:none -Werror -deprecation:false
//
//> using options -opt:inline:** -Wopt:none -Werror -deprecation:false

object Test extends App {
@deprecated("","") def f = 42
Expand Down

0 comments on commit 820ad16

Please sign in to comment.