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

Reformating breaks compilation when using scala3 rewritting setting #3623

Closed
almendar opened this issue Aug 30, 2023 · 0 comments · Fixed by #3624
Closed

Reformating breaks compilation when using scala3 rewritting setting #3623

almendar opened this issue Aug 30, 2023 · 0 comments · Fixed by #3624

Comments

@almendar
Copy link

almendar commented Aug 30, 2023

Please make sure that the issue is observable using the latest version of scalafmt and
within the scalafmt CLI: https://scalameta.org/scalafmt/docs/installation.html#cli

▶ scalafmt --version
scalafmt 3.7.13

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = "3.7.13"
runner.dialect = scala3
rewrite.scala3 = {
    convertToNewSyntax = true
    removeOptionalBraces = true
}

Command-line parameters (required)

When I run scalafmt via CLI like this: ▶ scalafmt src/main/scala/example/Main.scala

Steps

Given code like this:

package example

@main def main(args: String*): Unit =
  val list = List(1, 2, 3) map: x =>
    x + 1

Problem

Scalafmt formats code like this:

package example

@main def main(args: String*): Unit =
  val list = List(1, 2, 3) map: x => x + 1

Expectation

The code stopped compiling:

sbt:scalafmt_bug> compile
[info] compiling 1 Scala source to /Users/tkogut/scalafmt_bug/target/scala-3.3.0/classes ...
[error] -- [E018] Syntax Error: /Users/tkogut/scalafmt_bug/src/main/scala/example/Main.scala:4:30
[error] 4 |  val list = List(1, 2, 3) map: x => x + 1
[error]   |                              ^
[error]   |                              expression expected but : found
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] -- [E006] Not Found Error: /Users/tkogut/scalafmt_bug/src/main/scala/example/Main.scala:4:37
[error] 4 |  val list = List(1, 2, 3) map: x => x + 1
[error]   |                                     ^
[error]   |                                     Not found: x
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed Aug 30, 2023, 12:20:26 PM

Additional observation

@main def main(args: String*): Unit =
  val list = List(1, 2, 3).map: x =>
    x + 1

This works ok. Notice the . (dot) after map.

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