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

Unable to format when unnecessary parentheses and curly brackets are used. #716

Closed
tgodzik opened this Issue Feb 6, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@tgodzik
Contributor

tgodzik commented Feb 6, 2017

This template is a guideline, not a strict requirement.

  • Version: 0.5.4
  • Integration: IntelliJ
  • Configuration:
style=default

Unexpected formatting output

Obtained, scalafmt formats code like this:

class A {

  (Range(0, 10)).map { (i =>
      println{
        i
      }
    )
    }
}

Expected, I would like the formatted output to look like this:

class A {
  (Range(0, 10)).map { (i =>println{ i } ) }
}

Now it throws an error:

org.scalafmt.Error$FormatterOutputDoesNotParse: Formatter output does not parse:
[info] class A {
[info]
[info]   (Range(0, 10)).map { (i => println
[info]                                    ^
[info] <input>:3: error: ) expected but end of file found
[info] (Range(0, 10)).map { (i => println
[info]                                      ^
[info]
[info] class A {
[info]
[info]   (Range(0, 10)).map { (i => println
[info]   at org.scalafmt.util.FormatAssertions$class.assertFormatPreservesAst(FormatAssertions.scala:37)
[info]   at org.scalafmt.FormatTests.assertFormatPreservesAst(FormatTests.scala:32)
[info]   at org.scalafmt.FormatTests.run(FormatTests.scala:69)
[info]   at org.scalafmt.FormatTests$$anonfun$4.apply(FormatTests.scala:54)
[info]   at org.scalafmt.FormatTests$$anonfun$4.apply(FormatTests.scala:54)
[info]   at org.scalafmt.util.HasTests$$anonfun$runTest$2.apply$mcV$sp(HasTests.scala:156)
[info]   at org.scalafmt.util.HasTests$$anonfun$runTest$2.apply(HasTests.scala:151)
[info]   at org.scalafmt.util.HasTests$$anonfun$runTest$2.apply(HasTests.scala:151)
[info]   at org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)
[info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info]   ...

Tested using a stat file:

style = default
<<< ONLY unnecessary parantheses
class A {

  (Range(0, 10)).map { (i =>
      println{
        i
      }
    )
    }
}
>>>
class A {
  (Range(0, 10)).map { (i => println{i})}
}
@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Feb 6, 2017

Member

Thank you for reporting! I am able to reproduce. Is this a real-world example or are you fuzzing? You have an eye for finding scalafmt bugs :)

Note that the parentheses are redundant, using both parens and curly braces is like wearing a with suspenders!

Member

olafurpg commented Feb 6, 2017

Thank you for reporting! I am able to reproduce. Is this a real-world example or are you fuzzing? You have an eye for finding scalafmt bugs :)

Note that the parentheses are redundant, using both parens and curly braces is like wearing a with suspenders!

@tgodzik

This comment has been minimized.

Show comment
Hide comment
@tgodzik

tgodzik Feb 7, 2017

Contributor

It's just a thing I found in our code. I just removed the redundant parens from there, but I figured if someone added it then it's possible they'll do it again. It's not really world breaking, but I thought it's good to at least report it.

Contributor

tgodzik commented Feb 7, 2017

It's just a thing I found in our code. I just removed the redundant parens from there, but I figured if someone added it then it's possible they'll do it again. It's not really world breaking, but I thought it's good to at least report it.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Feb 7, 2017

Member

Definitely good to report. This is a bug.

Member

olafurpg commented Feb 7, 2017

Definitely good to report. This is a bug.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Mar 3, 2017

Member

This was caused by a problematic case in Router.scala that should be removed in the next major release, see #768

Member

olafurpg commented Mar 3, 2017

This was caused by a problematic case in Router.scala that should be removed in the next major release, see #768

@olafurpg olafurpg closed this Mar 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment