Skip to content

docs: add an example to -Yindent-colons section #10534

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

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/docs/reference/other-new-features/indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ xs.map:
y * y
```

Colons at the end of lines are their own token, distinct from normal `:`.
The Scala grammar is changed in this variant so that colons at end of lines are accepted at all points
where an opening brace enclosing a function argument is legal. Special provisions are taken so that method result types can still use a colon on the end of a line, followed by the actual type on the next.
The colon is usable not only for lambdas and by-name parameters, but
also even for ordinary parameters:

```scala
credentials ++ :
val file = Path.userHome / ".credentials"
if file.exists
then Seq(Credentials(file))
else Seq()
```

How does this syntax variant work? Colons at the end of lines are their own token, distinct from normal `:`.
The Scala grammar is changed so that colons at end of lines are accepted at all points
where an opening brace enclosing an argument is legal. Special provisions are taken so that method result types can still use a colon on the end of a line, followed by the actual type on the next.