scalameta / scalafmt

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

RedundantParens removes parens that are not redundant #4117

Closed agilesteel closed 1 month ago

agilesteel commented 1 month ago
version = "3.8.3"
maxColumn = 100
rewrite.rules = [ RedundantParens ]
runner.dialect = scala213

Steps

Given code like this:

object a {
  val b: Long = 1
}

(-a.b).toString

Problem

Scalafmt formats code like this:

-a.b.toString

Parens are removed and the code doesn't compile with

value unary_- is not a member of String

Expectation

I would like the formatted output to look like this:

(-a.b).toString // untouched

Workaround

Revert to v3.8.2 or disable formatting.

Note

This also happens in Scala3.

kitbellew commented 1 month ago

duplicate of #4116.