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

Using format: off doesn't prevent Search state exploded issue #3027

Closed
falconepl opened this issue Jan 4, 2022 · 0 comments · Fixed by #3029
Closed

Using format: off doesn't prevent Search state exploded issue #3027

falconepl opened this issue Jan 4, 2022 · 0 comments · Fixed by #3029

Comments

@falconepl
Copy link

I've recently found a case where // format: off doesn't prevent us from Search state exploded issue, for a deeply nested code. Here's a Scalafmt configuration and a minimal source code that allows to reproduce the issue...

Environment

Version: 3.3.1
Integration: sbt
Configuration:

version=3.3.1

align.arrowEnumeratorGenerator = true
align.tokens."+" = [{code = "="}, {code = "<-"}, {code = "extends"}, {code = "%"}, {code = "%%"}, {code = "->"}]
comments.wrap = standalone
comments.wrapStandaloneSlcAsSlc = true
maxColumn = 120
newlines.beforeCurlyLambdaParams = multilineWithCaseOnly
newlines.implicitParamListModifierPrefer = before
newlines.topLevelStatementBlankLines = [{blanks = 1}]
preset = IntelliJ
runner.dialect = Scala212Source3

rewrite.rules = [PreferCurlyFors, RedundantBraces, RedundantParens, SortModifiers]
rewrite.redundantBraces.generalExpressions = false
rewrite.redundantBraces.includeUnitMethods = false
rewrite.redundantBraces.methodBodies = false
rewrite.redundantBraces.stringInterpolation = true

Steps

Assume that we've got an object like this:

package minimal

// format: off
object SearchStateExploded {

  def someMethodCall(foo: String, bar: String) = s"$foo + $bar"

  val veryLongString =
    s"""
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
      ${someMethodCall(
          foo = "value",
          bar = "another value")}
    """

}
// format: on

Problem

We get Search state exploded despite of the fact that // format: off was used:

> scalafmt
[info] scalafmt: Formatting 1 Scala sources (/Users/someuser/scalafmtissue)...
[error] stack trace is suppressed; run last Compile / scalafmt for the full output
[error] (Compile / scalafmt) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: Search state exploded on ',∙bar[1291:1305]', line 49 [/Users/someuser/scalafmtissue/src/main/scala/minimal/SearchStateExploded.scala]

Expectation

Although Search state exploded could be expected for such a code snippet, it should be possible to avoid it when // format: off is used. It seems that it's a regression - the similar snippet also causes Search state exploded in Scalafmt 2.7.5 but using // format: off can prevent it

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.

1 participant