Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in -Wvalue-discard message, include type of discarded value #10092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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