-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fewer braces and lambda: incorrect indentation region detection #22193
Comments
The docs says https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html#indentation-and-braces-1 The assumed indentation width of a multiline region inside brackets or parentheses is:
So indenting (relative to
On the linked ticket, it's assumed that this behavior is a bug because the following works:
The difference is that fn2 uses a lookahead scanner to detect that arrow is followed by |
Assigning myself just to let you know I'm looking at it right now. It's actually simpler:
I think the reference omits the special case for colon. |
But the And if |
@kitbellew I'll answer more fully when my understanding has improved. It may just work under the "same width" exclusion, like a block following colon at EOL. The philosophical words I was about to write: regions are a scaffolding for when to infer indents and outdents. |
I added a WIP PR still in-progress... Edit: improved to make it less wrong. @kitbellew You may wish to review the two test files, which reflect your intuition that the lambda body only needs to be indented from the "enclosing" indentation width. The bug was that a fresh lookahead scanner recomputes its indentation width for whatever offset it starts at. That broke the condition that the arrow at EOL is followed by an indent. (Otherwise, function literals are agnostic about body syntax.) My previous guess about allowing indent at equal widths was a red herring, and the code comment I quoted was wrong. The alignment rule for
which looks stranger (because it doesn't align with the selector expression) than the aligned syntax I've come to prefer:
That is easy to scan because the match stops at "not a case". I was looking at:
but that makes no sense and quickly runs into difficulty:
which, now that I've dismissed it, also holds a certain eccentric appeal. |
Thank you for that, I wasn't expecting movement on this so soon. Checked the tests, added a comment.
Related to last comment but separate from this issue, happy to submit another issue if you agree. When I was dealing with formatting rules for fewer-braces, ran into problems (we usually indent continuation select statements):
the reason was that |
@kitbellew thanks, added those tests too, which just work. (Actually your example compiles before the fix. Maybe I'm missing what you mean.) (Maybe other compiler options are involved.) The dot rule is that the dot must differ from the two regions by more than one. Maybe I'll add a neg test as well, although the PR only touches "whether to parse" and not actual parsing logic. There may be an existing test. Added the 3.6.3 parse result as a test!
|
The dot rule will stop people from using
|
oh... i haven't checked this for a year, but let me try to find my old code which didn't work. |
Compiler version
Minimized code
Output
scastie marks two errors:
fn2
line withnot a legal formal parameter for a function literal
val x = env
line withNot found: env
Expectation
According to the documentation, the first argument clause (with
arg
andarg2
) does not start an indentation region, hence as long as the lambda body is indented relative tofn2
invocation, it should work.P.S. The problem was first reported in scalameta/scalafmt#4569.
The text was updated successfully, but these errors were encountered: