-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unit-Insertion works differently in Scala 2 & Scala 3 #12890
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
Comments
IIRC, I think this was intentional - an |
Yes, that's intentional. I am not sure whether Scala 2's behavior was an accident, or whether there was some specific motivation behind it. |
The behavior is specified:
Also the feature is not called "Unit insertion" (which sounds helpful) but "Value discard" (which sounds possibly dangerous). |
Is the Scala3 behavior documented anywhere? In http://dotty.epfl.ch/docs/reference/syntax.html, |
I saw a tailrec method of the form
|
Scala 3 handles unit-insertion differently to Scala 2
Compiler version
3.0.0 vs 2.13.6 - both using Scastie
Minimized code
Output - using Scala 3...
plus warning...
A pure expression does nothing in statement position; you may be omitting necessary parentheses
Expectation - as in Scala 2...
1 ()
plus no warning
Comments
Scala 3 does give the above warning about a pure expression and changing the code to the following works...
From @smarter ...
"it looks like unit-insertion is working differently in scala 2 and 3 (in scala 2 it only inserts Unit in the missing branch, in Scala 3 it inserts it in both branches)"
The text was updated successfully, but these errors were encountered: