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

Scalafmt Rewrite Is Not Value Preserving #1756

Closed
adamgfraser opened this issue Mar 1, 2020 · 4 comments · Fixed by #1757
Closed

Scalafmt Rewrite Is Not Value Preserving #1756

adamgfraser opened this issue Mar 1, 2020 · 4 comments · Fixed by #1757

Comments

@adamgfraser
Copy link

This template is a guideline, not a strict requirement.

  • Version: 0.5
  • Integration: IntelliJ
  • Configuration:
version = "2.4.2"
maxColumn = 120
align = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
spaces {
  inImportCurlyBraces = true
}
optIn.annotationNewlines = true

rewrite.rules = [SortImports, RedundantBraces]

Steps

Given code like this:

      childContext.onDone { _ =>
        val _ = self.withChildren(_.remove(childContext))
      }

When I run scalafmt like this:

scalafmt

Problem

Scalafmt formats code like this:

      childContext.onDone(_ => val _ = self.withChildren(_.remove(childContext)))

Expectation

I would like the formatted output to look like this:

      childContext.onDone { _ =>
        val _ = self.withChildren(_.remove(childContext))
      }
@kitbellew
Copy link
Collaborator

@adamgfraser could you explain the title of this issue, please? does it mean that the current formatting doesn't result in equivalent scala?

@adamgfraser
Copy link
Author

@kitbellew Sure, sorry. The original code is valid code that compiles. The rewritten code does not compile. The assignment syntax is only valid within a block.

@kitbellew
Copy link
Collaborator

@adamgfraser ah, thank you. a similar problem (#1718) was fixed in #1715 and released in 2.4.2. when i run your test on 2.4.2, it produces

childContext.onDone { _ => val _ = self.withChildren(_.remove(childContext)) }

are you certain you are experiencing it with 2.4.2 and not an earlier version?

@adamgfraser
Copy link
Author

@kitbellew Very certain. We encountered it just after merging a PR to update to 2.4.2.

kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 1, 2020
kitbellew added a commit that referenced this issue Mar 1, 2020
kitbellew added a commit that referenced this issue Mar 1, 2020
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