-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Strict mode for value discard warning #7716
Conversation
Disable dispensations under `-Ywarn-value-discard-strict`.
Continuing from your comments in #7563 (comment):
It's not a trick. There's no opting-out of value discarding in Scala. The best you can do is get warnings (and then choose if you want any warning to be fatal). However then you have to deal with the cases when you do want to discard a value. In that case the desire is (which started in #7530 and then #7560) to be explicit about wanting to discard the value. I don't think we should add a flag to disable how one opts out, even if it's an experimental -Y flag. Write a SIP to disable value discarding entirely, now that's an effort I would assist you with. |
@dwijnand It's a trick, I tell you. You can tell it's a trick because of the bug noted on the other ticket, where To make sure we're on the same page, we're still talking about enabling warnings, not forked code semantics. Anyway, the context is folks using Akka with Were I they, I wouldn't want to wonder if some weirdness is because I wrote something a certain way for some reason I don't know what, and now it doesn't work. In this question, the accepted answer had it wrong until help came along. Similarly for In this context, it's simplest to just give them a tool that removes all doubt -- see the doubts expressed on the other ticket. It's clear that the |
Before this is merged I'd like if it was clear what the intended goal is with introducing this. Particularly I'm wondering when it's expected this flag will be used, because I think it'll be so loud and noisy it'll at best only useful for gists and stackoverflow snippets, but won't ever be of use in a sizeable codebase. Are gists and stackoverflow snippets acceptable use cases for introducing a new experimental -Y flag? If type ascribing If |
Regarding the noisiness: Depends how far the project grew. It's always a tradeoff to enable it afterwards or not but when used from beginning it may prevent a lot of errors. It's definitely worth it. Discarded values often point to errors. At work we use wartremover's NonUnitStatement to help our newcomers: (i know this is about statements not value discarding at end of block)
(similar to real code written by a programmer unexperienced with scala) |
Even from the get go I don't think this option would survive because it means noise for each and every this-returning and non-unit returning method, with no cheap way to disable the warning. |
WIPing it until the concerns are sorted. I see it as just a way to turn warnings up or down; I understand Dale to be saying what's the point of turning it up if it introduces noise and reduces effectiveness. The orthogonal concerns include whether value discard is a good feature, and whether warnings can be filtered. Separately, I'll take a shot at filtering. That would not obviate this PR, maybe allow users to turn warnings up or down and then filter on the result. |
Filtering sound interesting. Besides that i like the strict mode. One can opt in and out with the preferred level of warnings. I first thought when #7563 gets released in 2.13.0 the behaviour can't be changed for 2.13.x. But adding strict mode later on would be possible, right? |
Disable dispensations under
-Ywarn-value-discard-strict
.