Backport -Xlint:deprecation

Backport from 01ea4f8bc2
This commit is contained in:
Lukas Rytz 2020-10-21 15:46:49 +02:00 committed by Dale Wijnand
parent ffef4d32aa
commit b14ba5d77d
3 changed files with 10 additions and 7 deletions

View File

@ -181,6 +181,7 @@ trait Warnings {
val StarsAlign = LintWarning("stars-align", "Pattern sequence wildcard must align with sequence component.")
val Constant = LintWarning("constant", "Evaluation of a constant arithmetic expression results in an error.")
val Unused = LintWarning("unused", "Enable -Ywarn-unused:imports,privates,locals,implicits,nowarn.")
val Deprecation = LintWarning("deprecation", "Enable -deprecation and also check @deprecated annotations.")
def allLintWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]]
}
@ -204,6 +205,7 @@ trait Warnings {
def warnStarsAlign = lint contains StarsAlign
def warnConstant = lint contains Constant
def lintUnused = lint contains Unused
def lintDeprecation = lint contains Deprecation
// Lint warnings that are currently -Y, but deprecated in that usage
@deprecated("Use warnAdaptedArgs", since="2.11.2")
@ -227,6 +229,7 @@ trait Warnings {
).withPostSetHook { s =>
if (s contains Unused) warnUnused.enable(UnusedWarnings.Linted)
else warnUnused.disable(UnusedWarnings.Linted)
if (s.contains(Deprecation) && deprecation.isDefault) deprecation.value = true
}
allLintWarnings foreach {

View File

@ -4035,7 +4035,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
case _ =>
reportAnnotationError(UnexpectedTreeAnnotationError(t, typedAnn))
}
if (annType.typeSymbol == DeprecatedAttr && sumSize(argss, 0) < 2)
if (annType.typeSymbol == DeprecatedAttr && settings.lintDeprecation && sumSize(argss, 0) < 2)
context.warning(ann.pos, """Specify both message and version: @deprecated("message", since = "1.0")""", WarningCategory.LintDeprecation)
if ((typedAnn.tpe == null) || typedAnn.tpe.isErroneous) ErroneousAnnotation

View File

@ -126,20 +126,19 @@ class WConfTest extends BytecodeTesting {
@Test
def default(): Unit = {
check(reports(code), List(s1a, s1b, s2, s3, s1c, l2, l9, l11, l13, l16)) // FIXME l2
check(reports(code, "cat=unchecked:ws"), List(s1a, s1b, s2, s3, s1c, s4, l2, l9, l11)) // FIXME l2
check(reports(code), List(s1a, s1b, s2, s3, s1c, l9, l11, l13, l16))
check(reports(code, "cat=unchecked:ws"), List(s1a, s1b, s2, s3, s1c, s4, l9, l11))
}
@Test
def noSummarizing(): Unit = {
check(reports(code, "any:w"), List(l2, l5a, l5b, l7, l9, l11, l13, l16, l20)) // FIXME l2
check(reports(code, "any:w"), List(l5a, l5b, l7, l9, l11, l13, l16, l20))
check(reports(code, "any:w", lint = true), List(l2, l5a, l5b, l7, l9, l11, l13, l16, l20, l23, l25))
}
@Test
def warnVerbose(): Unit = {
check(reports(code, "any:wv"), List(
l2.copy(_2 = "[lint-deprecation @ A] " + l2._2), // FIXME
l5a.copy(_2 = "[deprecation @ A.invokeDeprecated | origin=A.f | version=] " + l5a._2),
l5b.copy(_2 = "[deprecation @ A.invokeDeprecated | origin=A.g | version=1.2.3] " + l5b._2),
l7.copy(_2 = "[feature-reflective-calls @ A.featureReflectiveCalls] " + l7._2),
@ -210,10 +209,11 @@ class WConfTest extends BytecodeTesting {
@Test
def lint(): Unit = {
check(infos(code, "cat=lint:i"), List(l2)) // FIXME
check(infos(code, "cat=lint:i"), Nil)
check(infos(code, "cat=lint:i", lint = true), List(l2, l23))
check(reports(code, "any:s,cat=lint:ws", lint = true), Nil)
check(reports(code, "cat=lint:ws,any:s", lint = true), List((-1, "two lint warnings")))
//check(infos(code, "cat=lint-deprecation:i", lint = true), List(l2))
check(infos(code, "cat=lint-deprecation:i", lint = true), List(l2))
check(infos(code, "cat=lint-adapted-args:i", lint = true), List(l23))
}