scalameta / scalafmt

Code formatter for Scala
http://scalameta.org/scalafmt
Apache License 2.0
1.44k stars 276 forks source link

PreferCurlyFors generates illegal code (and it isn't curly either) #2695

Closed SethTisue closed 3 years ago

SethTisue commented 3 years ago

Steps

Given code like this:

object O {
  for (pos <- "a->1|b->2".split('|'); c = pos.split("->"))
  yield ()
}

When I run scalafmt like this:

scalafmt --config scalafmt.conf S.scala

Problem

Scalafmt formats code like this:

object O {
  for (
    pos <- "a->1|b->2".split('|')
    c = pos.split("->")
  )
    yield ()
}

which the compiler then actually rejects:

% scalac S.scala
S.scala:4: error: value c is not a member of Array[String]
possible cause: maybe a semicolon is missing before `value c`?
    c = pos.split("->")
    ^
1 error

Expectation

I would like the formatted output to look like this:

object O {
  for {
    pos <- "a->1|b->2".split('|')
    c = pos.split("->")
  }
    yield ()
}

Notes

this came up over at https://github.com/playframework/twirl/pull/437

SethTisue commented 3 years ago

thank you for the speedy fix! ❤️