Skip to content

Commit

Permalink
Merge pull request #10092 from SethTisue/include-type-in-value-discar…
Browse files Browse the repository at this point in the history
…d-message

in -Wvalue-discard message, include type of discarded value
  • Loading branch information
SethTisue committed Jul 28, 2022
2 parents e616e1d + fcd9886 commit 52e7c0f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
case (Apply(Select(receiver, _), _), SingleType(_, sym)) => sym == receiver.symbol
case _ => false
}
if (!isThisTypeResult && !explicitlyUnit(tree)) context.warning(tree.pos, "discarded non-Unit value", WarningCategory.WFlagValueDiscard)
if (!isThisTypeResult && !explicitlyUnit(tree))
context.warning(tree.pos, s"discarded non-Unit value of type ${tree.tpe}",
WarningCategory.WFlagValueDiscard)
}
@inline def warnNumericWiden(tpSym: Symbol, ptSym: Symbol): Unit =
if (!isPastTyper) {
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t12026.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
t12026.scala:11: warning: discarded non-Unit value
t12026.scala:11: warning: discarded non-Unit value of type Int
def f(): Unit = v()
^
error: No warnings can be incurred under -Werror.
Expand Down
8 changes: 4 additions & 4 deletions test/files/neg/t9847.check
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
t9847.scala:6: warning: discarded non-Unit value
t9847.scala:6: warning: discarded non-Unit value of type Int(42)
def f(): Unit = 42
^
t9847.scala:14: warning: discarded non-Unit value
t9847.scala:14: warning: discarded non-Unit value of type Int(1)
+ 1
^
t9847.scala:18: warning: discarded non-Unit value
t9847.scala:18: warning: discarded non-Unit value of type Int
x + 1
^
t9847.scala:21: warning: discarded non-Unit value
t9847.scala:21: warning: discarded non-Unit value of type Int
def j(): Unit = x + 1
^
t9847.scala:6: warning: a pure expression does nothing in statement position
Expand Down
4 changes: 2 additions & 2 deletions test/files/neg/value-discard.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
value-discard.scala:6: warning: discarded non-Unit value
value-discard.scala:6: warning: discarded non-Unit value of type Boolean
mutable.Set[String]().remove("") // expected to warn
^
value-discard.scala:13: warning: discarded non-Unit value
value-discard.scala:13: warning: discarded non-Unit value of type scala.collection.mutable.Set[String]
def subtract(): Unit = mutable.Set.empty[String].subtractOne("") // warn
^
value-discard.scala:17: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
Expand Down

0 comments on commit 52e7c0f

Please sign in to comment.