Skip to content

Commit

Permalink
Promote value discard to lint
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jun 3, 2020
1 parent 4fac59a commit 9bad1f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/compiler/scala/tools/nsc/settings/Warnings.scala
Expand Up @@ -112,7 +112,8 @@ trait Warnings {
)
) withAbbreviation "-Ywarn-macros"
val warnDeadCode = BooleanSetting("-Wdead-code", "Warn when dead code is identified.") withAbbreviation "-Ywarn-dead-code"
val warnValueDiscard = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.") withAbbreviation "-Ywarn-value-discard"
@deprecated("Use lintValueDiscard", since="2.13.3")
val warnValueDiscard = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.") withAbbreviation "-Ywarn-value-discard" withDeprecationMessage "Use -Xlint:value-discard"
val warnNumericWiden = BooleanSetting("-Wnumeric-widen", "Warn when numerics are widened.") withAbbreviation "-Ywarn-numeric-widen"
val warnOctalLiteral = BooleanSetting("-Woctal-literal", "Warn on obsolete octal syntax.") withAbbreviation "-Ywarn-octal-literal"

Expand Down Expand Up @@ -149,7 +150,7 @@ trait Warnings {
val warnExtraImplicit = BooleanSetting("-Wextra-implicit", "Warn when more than one implicit parameter section is defined.") withAbbreviation "-Ywarn-extra-implicit"

@deprecated("Use lintImplicitRecursion", since="2.13.3")
val warnSelfImplicit = BooleanSetting("-Wself-implicit", "An implicit resolves to an enclosing definition.") withAbbreviation "-Ywarn-self-implicit" withDeprecationMessage "Use -Xlint:implicit-recurses"
val warnSelfImplicit = BooleanSetting("-Wself-implicit", "An implicit resolves to an enclosing definition.") withAbbreviation "-Ywarn-self-implicit" withDeprecationMessage "Use -Xlint:implicit-recursion"

// Experimental lint warnings that are turned off, but which could be turned on programmatically.
// They are not activated by -Xlint and can't be enabled on the command line because they are not
Expand Down Expand Up @@ -194,7 +195,8 @@ trait Warnings {
val RecurseWithDefault = LintWarning("recurse-with-default", "Recursive call used default argument.")
val UnitSpecialization = LintWarning("unit-special", "Warn for specialization of Unit in parameter position.")
val MultiargInfix = LintWarning("multiarg-infix", "Infix operator was defined or used with multiarg operand.")
val ImplicitRecurses = LintWarning("implicit-recurses", "Implicit resolves to an enclosing definition.")
val ImplicitRecursion = LintWarning("implicit-recursion", "Implicit resolves to an enclosing definition.")
val ValueDiscard = LintWarning("value-discard", "A non-Unit value was not used because Unit was required.")

def allLintWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]]
}
Expand Down Expand Up @@ -227,7 +229,8 @@ trait Warnings {
def warnRecurseWithDefault = lint contains RecurseWithDefault
def unitSpecialization = lint contains UnitSpecialization
def multiargInfix = lint contains MultiargInfix
def lintImplicitRecursion = lint.contains(ImplicitRecurses) || warnSelfImplicit
def lintImplicitRecursion = lint.contains(ImplicitRecursion) || warnSelfImplicit
def lintValueDiscard = lint.contains(ValueDiscard) || warnValueDiscard

// The Xlint warning group.
val lint = MultiChoiceSetting(
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -1144,7 +1144,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
@inline def tpdPos(transformed: Tree) = typedPos(tree.pos, mode, pt)(transformed)
@inline def tpd(transformed: Tree) = typed(transformed, mode, pt)

@inline def warnValueDiscard(): Unit = if (!isPastTyper && settings.warnValueDiscard) {
@inline def warnValueDiscard(): Unit = if (!isPastTyper && settings.lintValueDiscard) {
def isThisTypeResult = (tree, tree.tpe) match {
case (Apply(Select(receiver, _), _), SingleType(_, sym)) => sym == receiver.symbol
case _ => false
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/implicitly-self.scala
@@ -1,4 +1,4 @@
// scalac: -Werror -Xlint:implicit-recurses
// scalac: -Werror -Xlint:implicit-recursion
//

trait TC[A] { def ix: Int }
Expand Down
2 changes: 1 addition & 1 deletion test/files/pos/t11813.scala
@@ -1,4 +1,4 @@
// scalac: -Werror -Xlint:implicit-recurses
// scalac: -Werror -Xlint:implicit-recursion
//
package warner

Expand Down

0 comments on commit 9bad1f2

Please sign in to comment.