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

Add note about Scala 3 compiler flags #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ivan-klass
Copy link

The import-guarded feature is safe when proper compiler flags are there

@ivan-klass ivan-klass requested a review from raquo as a code owner November 28, 2024 23:55
@raquo
Copy link
Owner

raquo commented Nov 30, 2024

I wish -Wvalue-discard could save us, but sadly, it won't.

Take this for example:

          val v = Var(0)
          div(
            text <-- v,
            onClick.mapTo(v.now() + 1) --> { if (v.now() < 5) v.writer }
          )

With -Wvalue-discard, it gives a warning, yes. But it warns us that we're discarding v.writer, not that we're discarding { if (v.now() < 5) v.writer }. This warning is entirely because of this bug: scala/scala3#20450. It wasn't there in earlier versions of Scala 3, and it will be fixed eventually. See also the poster's subsequent comment that explains the difference in intended behaviour between Scala 2 and 3.

@ivan-klass
Copy link
Author

it gives a warning, yes. But it warns us that we're discarding v.writer, not that we're discarding { if (v.now() < 5) v.writer }

I'm sorry, I didn't get it.
First, there's still a warning. If there's an error in one part of the expression, it means the whole expression has an error - i.e. if there's a code considered "dirty", the entire program is "dirty".

Second, the problem in your example is indeed that we discard the writer - so it's not subscribed to clicks. The branch itself is executed - see scastie example.

@raquo
Copy link
Owner

raquo commented Dec 5, 2024

First, there's still a warning.

My understanding is that this warning is considered a "bug" in Scala, the one I linked. Personally, I don't think it should be considered a bug, but as today, it is. I've just added a comment to that issue with my counter-argument to the proposed change, but until and unless they change their mind, this warning is sadly slated to go away in a future release of Scala 3.

the problem in your example is indeed that we discard the writer - so it's not subscribed to clicks. The branch itself is executed.

Well, yes. If the user tries to return the writer conditionally, it's because they expect to trigger it conditionally. If the writer is ignored without a warning instead, that's a problem.

BTW I looked into the history a bit, and it turns out that the wvalue-discard compiler flag was only implemented in Scala 3.3.0 – I probably wrote those docs before I switched to that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants