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

RedundantBraces rewrite removes parentheses that are required syntactically #3540

Closed
mrdziuban opened this issue May 2, 2023 · 1 comment · Fixed by #3545
Closed

RedundantBraces rewrite removes parentheses that are required syntactically #3540

mrdziuban opened this issue May 2, 2023 · 1 comment · Fixed by #3545

Comments

@mrdziuban
Copy link

Configuration (required)

version = "3.7.3"
runner.dialect = scala213
rewrite.rules = [RedundantBraces]

Command-line parameters (required)

scalafmt --config /path/to/.scalafmt.conf /path/to/Foo.scala

Steps

Given code like this:

class Foo[A](f: A => Unit)
object Bar extends Foo[(Int, String)]({ case (i, s) => () })

Problem

Scalafmt removes the parentheses around the function passed to the Foo constructor, like this:

class Foo[A](f: A => Unit)
object Bar extends Foo[(Int, String)] { case (i, s) => () }

Expectation

The parentheses should remain as they're required for the syntax to be valid. Maybe this is a nuance of functions passed to class constructors.

Workaround

Other than disabling the RedundantBraces rewrite, the only other workaround I've found is to add a // format: off comment to disable scalafmt on this code.

@DorQuendi
Copy link

I have the same issue, where redundant braces are removed, where they are required by the syntax. Specifically in two cases.

  1. code with multiple parameter sets followed by dot notation call
    (a(x)(y)).call(...)
    is rewritten to invalid syntax:
    a(x)(y).call(...)
  2. braces are removed also from constructors with 0 parameters:
    ClassA()
    is rewritten to:
    ClassA
    While this is ok in scala, it is an issue when using native Java classes.

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.

2 participants