-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Clarification of intended ’if … then’ new control syntax interaction with newlines #12757
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
(Description edited.) |
This is analogous to "Braced" or "block" behavior, but with the braces optional, needs an indent:
Otherwise, the
The potential for ambiguity:
There is an intuition that it should take up to the
Usual example where we need to add grouping parens:
I don't remember if they plan to keep traditional paren syntax; if quiet syntax becomes standard, then they can vacuum to the next Footnote: I tried out 3-space indents here! but frankly, with top-level defs, I don't really indent much any more. |
This one is pretty weird: def f =
if
x.exists
(x => x == 10) then
println("Yes")
else
println("No") and |
There is the (provisional) rule for "parsing of legacy code with ad-hoc layout." https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html |
In a statement like this ```scala if foo (bar) then ``` we would never expect a semicolon to be inserted between `foo` and `bar`. The `foo` would need to be indented itself for this to happen. So, the following is OK ```scala if val x = ... x > 0 then ``` But the following is not: ```scala if val x = ... x > 0 ``` Fixes scala#12757
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.0.0
Minimized code
This compiles:
But this does not:
Expectation
Given that Scala 3 allows method calls like this in other contexts:
the
if x.exists …
in the second example above seems at least intuitively plausible, even though it doesn’t compile. Clarification as to whether or not that latter example should be considered valid would be appreciated. (The New Control Syntax page doesn’t obviously settle the matter.)My doubt here arises from:
whether the newline after the
if x.exists
should terminate theif
condition, as it currently seems to do in Scala 3.0.0;or whether the
if
condition should instead be considered to continue up until the followingthen
, the newline before the indented argument tox.exists
being treated as it would be in other contexts.Interestingly, this does compile:
As does:
Note that this question arose in this Scalafmt-related comment.
The text was updated successfully, but these errors were encountered: