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
SI-9847 Nuance pure expr statement warning #5266
Conversation
Passing a flag to suppress the check for blocks is suboptimal. An alternative would be just to shorten the original warning and not be fancy; and avoid lint territory. |
This failing checkfile change for
|
Clarify the current warning, which means that an expression split over multiple lines may not be parsed as naively expected. When typing a block, attempt minor nuance. For instance, a single expression is not in need of parens. Try to avoid duplicate warnings for expressions that were adapted away from result position.
^ | ||
t9847.scala:4: warning: a pure expression does nothing in statement position | ||
def f(): Unit = 42 | ||
^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there some logic in place to only report a single warning per position?
I wonder why we get both warnings here. With M5 I don't get the discarded non-Unit value
one:
Welcome to Scala 2.12.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> def f(): Unit = 42
<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
def f(): Unit = 42
^
f: ()Unit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractReporter suppresses multiple ERROR or lower-priority messages (warnings in presence of errors).
The value discard is a flag:
$ scala -Ywarn-value-discard
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> def f: Unit = 42
<console>:11: warning: discarded non-Unit value
def f: Unit = 42
^
<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
def f: Unit = 42
^
f: Unit
scala> :quit
$ scalam -Ywarn-value-discard
Welcome to Scala 2.12.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> def f: Unit = 42
<console>:11: warning: discarded non-Unit value
def f: Unit = 42
^
<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
def f: Unit = 42
^
f: Unit
scala> :quit
$ skala -Ywarn-value-discard
Welcome to Scala 2.12.0-20160708-085210-f805cf5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> def f: Unit = 42
<console>:11: warning: discarded non-Unit value
def f: Unit = 42
^
<console>:11: warning: a pure expression does nothing in statement position
def f: Unit = 42
^
f: Unit
scala> :quit
(Adding WIP label to indicate this is awaiting an A for the reviewer's Q) |
I tried to add the WTF label, but I guess I don't have the authority. |
And that's why. |
LGTM |
Clarify the current warning, which means that an expression
split over multiple lines may not be parsed as naively expected.
When typing a block, attempt minor nuance. For instance, a
single expression is not in need of parens. Try to avoid
duplicate warnings for expressions that were adapted away
from result position.