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

SI-9847 Nuance pure expr statement warning #5266

Merged
merged 1 commit into from Aug 15, 2016

Conversation

som-snytt
Copy link
Contributor

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.

@som-snytt
Copy link
Contributor Author

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.

@som-snytt
Copy link
Contributor Author

som-snytt commented Jul 8, 2016

This failing checkfile change for run/t7747-repl.scala happened on another PR, too. It passes on my machine:

-res3: List[Product with Serializable] = List(BippyBups(), PuppyPups(), Bingo())
+res3: List[Serializable with Product] = List(BippyBups(), PuppyPups(), Bingo())

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.
@adriaanm adriaanm added this to the 2.12.0-RC1 milestone Jul 26, 2016
@adriaanm adriaanm self-assigned this Aug 2, 2016
^
t9847.scala:4: warning: a pure expression does nothing in statement position
def f(): Unit = 42
^
Copy link
Member

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

Copy link
Contributor Author

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

@adriaanm
Copy link
Contributor

(Adding WIP label to indicate this is awaiting an A for the reviewer's Q)

@adriaanm adriaanm added the WIP label Aug 11, 2016
@som-snytt
Copy link
Contributor Author

I tried to add the WTF label, but I guess I don't have the authority.

@adriaanm
Copy link
Contributor

And that's why.

@adriaanm adriaanm removed the WIP label Aug 13, 2016
@adriaanm
Copy link
Contributor

LGTM

@adriaanm adriaanm merged commit 99f8b28 into scala:2.12.x Aug 15, 2016
@adriaanm adriaanm added the 2.12 label Oct 29, 2016
@som-snytt som-snytt deleted the issue/9847 branch November 13, 2016 18:41
@som-snytt som-snytt restored the issue/9847 branch June 26, 2020 20:47
@som-snytt som-snytt deleted the issue/9847 branch December 19, 2020 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants