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

Incorrect code generated when formatting valid code using fewer braces syntax #3447

Closed
odd opened this issue Jan 22, 2023 · 0 comments · Fixed by #3446
Closed

Incorrect code generated when formatting valid code using fewer braces syntax #3447

odd opened this issue Jan 22, 2023 · 0 comments · Fixed by #3446

Comments

@odd
Copy link

odd commented Jan 22, 2023

Configuration

version = 3.7.0
runner.dialect = scala3

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt --stdin

Steps

Given code like this:

def sum(xs: List[Int]): Int =
  xs.foldLeft(0):
    case (a, b) => a + b

Problem

Scalafmt formats code like this:

def sum(xs: List[Int]): Int =
  xs.foldLeft(0):
  case (a, b) => a + b

Expectation

I would like the formatted output to look like this:

def sum(xs: List[Int]): Int =
  xs.foldLeft(0):
    case (a, b) => a + b

Workaround

Use braces instead of indentation for the last parameter to foldLeft:

def sum(xs: List[Int]): Int =
  xs.foldLeft(0) {
    case (a, b) => a + b
  }

Notes

Only fails on Scala 3.3 onwards (I used 3.3.0-RC1-bin-20230118-9337bd6-NIGHTLY) since the original syntax is only valid with the Fewer Braces-feature (which has been merged into Scala 3.3)

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 a pull request may close this issue.

1 participant