-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Suppress value discarding warning when ascribed to Unit #7560
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
Conversation
|
/cc @som-snytt who'll be interested 😄 |
3b19fe8 to
38d0b82
Compare
|
👍 on the strategy. I can't evaluate the implementation, unfortunately. |
| t9847.scala:7: warning: discarded non-Unit value | ||
| def g = (42: Unit) | ||
| ^ | ||
| t9847.scala:7: warning: a pure expression does nothing in statement position |
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.
Perhaps the pure expr warning is exactly the same use case?
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.
I don't understand the (seemingly to me) subtle differences between the two.
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.
"statement position" means not at the end of the block, which is "result position." "Value discard" (or "unit insertion") moves an expression into statement position, so it's doubly warned. I think that, for consistency, it should also not warn on "hi" in the example below. It's a lame use case, and the compiler is trying to warn only in limited cases (non-side-effecty). But it's easy to use the same notational cue and not warn.
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.
I don't see the "hi" example.
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.
I re-commented, which is what RC is for.
and and means I only wonder when is it safe to remove an attachment. I see the discard warning is on "last try", but retrying makes me suspicious of losing information too early. Also I see REPL's reporter has wrong indentation for pasted code. It can leverage |
|
Did I post this right? The goal is to not warn where it says |
|
@som-snytt I agree, but I'm not sure if I'll get a chance to look into that soon (too many things on the go). |
som-snytt
left a comment
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.
I brought the commit over to a superseding PR.
| if (!isThisTypeResult) context.warning(tree.pos, "discarded non-Unit value") | ||
| def wasTypedExpectingUnit = { | ||
| tree.attachments.contains[TypedExpectingUnitAttachment.type] && { | ||
| tree.attachments.remove[TypedExpectingUnitAttachment.type] // cleanup |
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.
This doesn't actually clean up, because this is not mutation. Normally, tree.getAndRemoveAttachment, but here it doesn't work to remove the attachment, as the tree will be seen again after adaptation and it will be checked again for expr in statement position warning.
|
Probably it's not annoying if I close this. |
No description provided.