You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formatted for/yield blocks with long variable names fail to compile. scalafmt inserts a newline, which breaks code using significant indentation.
Configuration
version = 3.8.3
runner.dialect = scala3
Command-line parameters
When I run scalafmt via CLI like this: scalafmt reproduction.scala
Steps
Given code like this:
valloremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu:Option[Int] =Some(1)
valexpression=for (
x <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu;
y <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
) yield x + y
Problem
Scalafmt formats code like this:
valloremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu:Option[Int] =Some(1)
valexpression=for (
x <-
loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu;
y <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
) yield x + y
This fails to compile with:
λ> scala-cli compile reproduction.scala
Compiling project (Scala 3.2.2, JVM)
[error] ./reproduction.scala:7:5
[error] expression expected but <- found
[error] y <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
[error] ^^
[error] ./reproduction.scala:6:5
[error] value y is not a member of Option[Int].
[error] Note that `y` is treated as an infix operator in Scala 3.
[error] If you do not want that, insert a `;` or empty line in front
[error] or drop any spaces behind the operator.
Expectation
I would like the formatted output to compile.
valloremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu:Option[Int] =Some(1)
valexpression=for (
x <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu;
y <- loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
) yield x + y
Workaround
The indentation is not introduced if maxColumns is increased, e.g. maxColumns=100. It is not introduced if the variable name is shorter in length.
The text was updated successfully, but these errors were encountered:
zainab-ali
changed the title
for/yield blocks with newlines fail to compile due to significant indentationscalafmt breaks for/yield blocks using significant indentation
Sep 9, 2024
my guess is, if you're using scala3 (with optional braces), another workaround is:
val expression = for
x <-
loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
y <-
loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididu
yield x + y
Formatted for/yield blocks with long variable names fail to compile.
scalafmt
inserts a newline, which breaks code using significant indentation.Configuration
Command-line parameters
When I run scalafmt via CLI like this:
scalafmt reproduction.scala
Steps
Given code like this:
Problem
Scalafmt formats code like this:
This fails to compile with:
Expectation
I would like the formatted output to compile.
Workaround
The indentation is not introduced if
maxColumns
is increased, e.g.maxColumns=100
. It is not introduced if the variable name is shorter in length.The text was updated successfully, but these errors were encountered: