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

New version 2.4.0 breaks some code #1707

Closed
gvolpe opened this issue Feb 15, 2020 · 5 comments · Fixed by #1709
Closed

New version 2.4.0 breaks some code #1707

gvolpe opened this issue Feb 15, 2020 · 5 comments · Fixed by #1709

Comments

@gvolpe
Copy link

gvolpe commented Feb 15, 2020

Problem with v2.4.0

Given code like this:

.flatMap { implicit logger: Logger[IO] => 
  program
}

When I run scalafmt it gets formatted as below:

.flatMap(implicit logger: Logger[IO] => program)

Which doesn't compile.

CI Build error

Here's the PR updating scalafmt: profunktor/redis4cats#224

Here's the full CI build error: https://github.com/profunktor/redis4cats/pull/224/checks?check_run_id=447840196

[error] /home/runner/work/redis4cats/redis4cats/modules/examples/src/main/scala/dev/profunktor/redis4cats/LoggerIOApp.scala:38:54: '=>' expected but ')' found.
[error]       .flatMap(implicit logger: Logger[IO] => program)
[error]                                                      ^
[error] /home/runner/work/redis4cats/redis4cats/modules/examples/src/main/scala/dev/profunktor/redis4cats/LoggerIOApp.scala:41:1: illegal start of simple expression
[error] }
[error] ^
[error] two errors found
@kitbellew
Copy link
Collaborator

@gvolpe thank you for reporting. to reproduce the problem, could you share:

  • configuration
  • a little more code

@gvolpe
Copy link
Author

gvolpe commented Feb 15, 2020

Sure, here's my configuration:

version                                      = "2.3.2"
align.openParenCallSite                      = false
align.tokens                                 = ["%", "%%", {code = "=>", owner = "Case"}, {code = "=", owner = "(Enumerator.Val|Defn.(Va(l|r)|Def|Type))"}, ]
align.arrowEnumeratorGenerator               = true
binPack.parentConstructors                   = false
danglingParentheses                          = true
maxColumn                                    = 120
newlines.afterImplicitKWInVerticalMultiline  = true
newlines.beforeImplicitKWInVerticalMultiline = true
project.excludeFilters                       = [ .scalafmt.conf ]
project.git                                  = true
rewrite.rules                                = [PreferCurlyFors, RedundantBraces, RedundantParens, SortImports]
spaces.inImportCurlyBraces                   = true
style                                        = defaultWithAlign
unindentTopLevelOperators                    = true

rewriteTokens {
  "⇒" = "=>"
  "→" = "->"
  "←" = "<-"
}

If I update to 2.4.0 I get this issue.

Code

override def run(args: List[String]): IO[ExitCode] =
  Slf4jLogger
    .create[IO]
    .flatMap { implicit logger: Logger[IO] =>
      program
    }
    .as(ExitCode.Success)

Here's the source code.

@rossabaker
Copy link

I'm facing a similar issue rewriting {} to (). On [ths http4s commit](https://github.com/http4s/http4s/tree/d568e34db6441af38eb1ae8763ab9e8faddc940e), after running core/scalafmtAll, we get the following diff on QueryParam.scala`:

    }
 
   def instantQueryParamEncoder(formatter: DateTimeFormatter): QueryParamEncoder[Instant] =
-    QueryParamEncoder[String].contramap[Instant] { i: Instant =>
-      formatter.format(i)
-    }
+    QueryParamEncoder[String].contramap[Instant](i: Instant => formatter.format(i))
 
   @deprecated("Use QueryParamEncoder[U].contramap(f)", "0.16")
   def encodeBy[T, U](f: T => U)(

This fails to compile:

sbt:http4s> test:compile
[info] Compiling 32 Scala sources to /home/ross/src/http4s/core/target/scala-2.13/classes ...
[error] /home/ross/src/http4s/core/src/main/scala/org/http4s/QueryParam.scala:94:80: ')' expected but '(' found.
[error]     QueryParamEncoder[String].contramap[Instant](i: Instant => formatter.format(i))
[error]                                                                                ^
[error] /home/ross/src/http4s/core/src/main/scala/org/http4s/QueryParam.scala:94:83: ';' expected but ')' found.
[error]     QueryParamEncoder[String].contramap[Instant](i: Instant => formatter.format(i))
[error]                                                                                   ^
[error] two errors found
/home/ross/src/http4s/core/src/main/scala/org/http4s/QueryParam.scala:94: error: ) expected but ( found
    QueryParamEncoder[String].contramap[Instant](i: Instant => formatter.format(i))
                                                                               ^
[error] (core / Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Feb 15, 2020 11:26:00 AM

kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 15, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 15, 2020
We can't rewrite a lambda unless it has parens around parameters or one
simple parameter without a type.

Fixes scalameta#1707.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 15, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 15, 2020
We can't rewrite a lambda unless it has parens around parameters or one
simple parameter without a type.

Fixes scalameta#1707.
Fixes scalameta#1708.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 15, 2020
We can't rewrite a lambda unless it has parens around parameters or one
simple parameter without a type.

Fixes scalameta#1707.
Fixes scalameta#1708.
kitbellew added a commit that referenced this issue Feb 16, 2020
We can't rewrite a lambda unless it has parens around parameters or one
simple parameter without a type.

Fixes #1707.
Fixes #1708.
@kitbellew
Copy link
Collaborator

@gvolpe please try v2.4.1

@gvolpe
Copy link
Author

gvolpe commented Feb 16, 2020

It works! Thanks, @kitbellew 🚀

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.

3 participants