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

Orphan parens error #3496

Closed
jxnu-liguobin opened this issue Mar 10, 2023 · 7 comments · Fixed by #3513
Closed

Orphan parens error #3496

jxnu-liguobin opened this issue Mar 10, 2023 · 7 comments · Fixed by #3513
Assignees

Comments

@jxnu-liguobin
Copy link

jxnu-liguobin commented Mar 10, 2023

Configuration (required)

version = 3.7.2
runner.dialect = scala3
project.git = true
preset = default
maxColumn = 120
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings.blankFirstLine = yes
docstrings.style = SpaceAsterisk
docstrings.removeEmpty = true
docstrings.wrap = false
docstrings.forceBlankLineBefore = true
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false
rewrite.rules = [RedundantBraces]
rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = true
rewrite.redundantBraces.generalExpressions = false
rewriteTokens = {
  "⇒": "=>"
  "→": "->"
  "←": "<-"
}

project.excludePaths = ["glob:**/scalafix/input/**", "glob:**/scalafix/output/**"]

fileOverride {
  ".sbt" {
    runner.dialect = sbt1
  }
  "glob:**/star-sbt-plugin/src/**.scala" {
    rewrite.scala3.convertToNewSyntax = false
    rewrite.scala3.removeOptionalBraces = false
  }
  "glob:**/star-codegen/src/**.scala" {
    rewrite.scala3.convertToNewSyntax = false
    rewrite.scala3.removeOptionalBraces = false
  }
  "glob:**/project/**.scala" {
    rewrite.scala3.convertToNewSyntax = false
    rewrite.scala3.removeOptionalBraces = false
  }
}

Steps

Given code like this:

  implicit def map: Array[Any] => List[String] = a =>
    a.map (ae => {
      ae match
        case s: String => s
        case _ => ae.toString
    }).toList

Problem

get error after executing sbt scalafmt:
image

This is OK

  implicit def map: Array[Any] => List[String] = a =>
    a.map { ae => {
        ae match
          case s: String => s
          case _ => ae.toString
      }
    }.toList
@kitbellew
Copy link
Collaborator

@jxnu-liguobin two requests:

  • could you please remove from your description the original instructions, and keep only our questions and your answers to them?
  • can you please recheck your submission examples; the part containing original code doesn't correspond to scalafmt-formatted code, so it's not clear how to reproduce and what to expect

@kitbellew
Copy link
Collaborator

also, you seem to have ignored the instructions. version 3.5.9 is not latest. please use the latest version and verify.

@jxnu-liguobin
Copy link
Author

also, you seem to have ignored the instructions. version 3.5.9 is not latest. please use the latest version and verify.

Updated

@kitbellew
Copy link
Collaborator

Problem

get error after executing sbt scalafmt: image

Can you please verify using the scalafmt command-line interface, just like the issue instructions mentioned? The error might be coming from sbt, so only CLI is requested.

@jxnu-liguobin
Copy link
Author

./scalafmt will still get the same error

 org.scalafmt.cli.FailedToFormat: /Users/liguobin/Work/star-authority/star-auth-infra/src/main/scala/fc/star/auth/infra/repository/syntax/AuthPermissionTable.scala
Caused by: java.lang.IllegalArgumentException: Orphan parens ([412]()
        at org.scalafmt.util.TreeOps$.getMatchingParentheses(TreeOps.scala:210)
        at org.scalafmt.internal.FormatTokens.org$scalafmt$internal$FormatTokens$$matchingParentheses$lzycompute(FormatTokens.         Reformatting...
    4.2%at org.scalafmt.internal.FormatTokens.org$scalafmt$internal$FormatTokens$$matchingParentheses(FormatTokens.scala:24)
        at org.scalafmt.internal.FormatTokens.matchingOpt(FormatTokens.scala:80)
        at org.scalafmt.internal.FormatOps.$anonfun$getForceConfigStyle$2(FormatOps.scala:1171)
        at org.scalafmt.internal.FormatOps.$anonfun$getForceConfigStyle$2$adapted(FormatOps.scala:1161)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
        at org.scalafmt.internal.FormatTokens.foreach(FormatTokens.scala:12)
        at org.scalafmt.internal.FormatOps.getForceConfigStyle(FormatOps.scala:1161)
        at org.scalafmt.internal.FormatOps.<init>(FormatOps.scala:74)
        at org.scalafmt.Scalafmt$.$anonfun$doFormatOne$4(Scalafmt.scala:153)
        at scala.meta.parsers.Parsed.fold(Errors.scala:12)
        at scala.meta.parsers.Parsed.fold$(Errors.scala:11)
        at scala.meta.parsers.Parsed$Success.fold(Errors.scala:26)
        at org.scalafmt.Scalafmt$.org$scalafmt$Scalafmt$$doFormatOne(Scalafmt.scala:152)
        at org.scalafmt.Scalafmt$.doFormat(Scalafmt.scala:126)
        at org.scalafmt.Scalafmt$.formatCodeWithStyle(Scalafmt.scala:91)
        at org.scalafmt.Scalafmt$.$anonfun$formatCode$3(Scalafmt.scala:78)
        at scala.util.Success.fold(Try.scala:281)
        at org.scalafmt.Scalafmt$.formatCode(Scalafmt.scala:78)
        at org.scalafmt.Scalafmt$.format(Scalafmt.scala:59)
        at org.scalafmt.Scalafmt.format(Scalafmt.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.scalafmt.dynamic.ScalafmtReflect.$anonfun$tryFormat$1(ScalafmtReflect.scala:110)
        at scala.util.Try$.apply(Try.scala:210)
        at org.scalafmt.dynamic.ScalafmtReflect.tryFormat(ScalafmtReflect.scala:106)
        at org.scalafmt.dynamic.ScalafmtReflectConfig.tryFormat(ScalafmtReflectConfig.scala:95)
        at org.scalafmt.dynamic.ScalafmtDynamicSession.$anonfun$tryForceFormat$1(ScalafmtDynamicSession.scala:50)
        at scala.util.Success.flatMap(Try.scala:258)
        at org.scalafmt.dynamic.ScalafmtDynamicSession.tryForceFormat(ScalafmtDynamicSession.scala:50)
        at org.scalafmt.dynamic.ScalafmtDynamicSession.tryFormat(ScalafmtDynamicSession.scala:37)
        at org.scalafmt.dynamic.ScalafmtDynamicSession.format(ScalafmtDynamicSession.scala:19)
        at org.scalafmt.cli.ScalafmtDynamicRunner$.handleFile(ScalafmtDynamicRunner.scala:79)
        at org.scalafmt.cli.ScalafmtDynamicRunner$.$anonfun$run$7(ScalafmtDynamicRunner.scala:52)
        at org.scalafmt.cli.ScalafmtDynamicRunner$.$anonfun$run$7$adapted(ScalafmtDynamicRunner.scala:50)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1293)
        at scala.collection.parallel.ParIterableLike$Foreach.leaf(ParIterableLike.scala:938)
        at scala.collection.parallel.Task.$anonfun$tryLeaf$1(Tasks.scala:52)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
        at scala.util.control.Breaks$$anon$1.catchBreak(Breaks.scala:97)
        at scala.collection.parallel.Task.tryLeaf(Tasks.scala:55)
        at scala.collection.parallel.Task.tryLeaf$(Tasks.scala:49)
        at scala.collection.parallel.ParIterableLike$Foreach.tryLeaf(ParIterableLike.scala:935)
        at scala.collection.parallel.AdaptiveWorkStealingTasks$AWSTWrappedTask.internal(Tasks.scala:159)
        at scala.collection.parallel.AdaptiveWorkStealingTasks$AWSTWrappedTask.internal$(Tasks.scala:156)
        at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$AWSFJTWrappedTask.internal(Tasks.scala:304)
        at scala.collection.parallel.AdaptiveWorkStealingTasks$AWSTWrappedTask.compute(Tasks.scala:149)
        at scala.collection.parallel.AdaptiveWorkStealingTasks$AWSTWrappedTask.compute$(Tasks.scala:148)
        at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$AWSFJTWrappedTask.compute(Tasks.scala:304)
        at java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)

@davesmith00000
Copy link

In case it helps, I was getting the same error in both the metals logs and using the cli with scalafmt 3.5.2, but on upgrading to 3.7.2 (after reading this issue), the problem seems to have been resolved (in my case):

Caused by: java.lang.IllegalArgumentException: Orphan parens ([4533]()

Same sort of thing as @jxnu-liguobin reported. This code (Scala 3) compiles fine and works, but showed the error during formatting:

  val applyAlpha: Layer => SignalFunction[Double, Layer] = l =>
    SignalFunction(d =>
      val material = l.blending.map(b => b.blendMaterial) match
        case Some(m) => m
        case None    => BlendMaterial.BlendEffects.None

      material match
        case m: BlendMaterial.BlendEffects =>
          l.withBlendMaterial(m.withAlpha(d))
        case _ => l
    )  // <-- Note the bracket type

This version works fine, all I've done is change the parenthesis to curly braces after SignalFunction:

  val applyAlpha: Layer => SignalFunction[Double, Layer] = l =>
    SignalFunction { d =>
      val material = l.blending.map(b => b.blendMaterial) match
        case Some(m) => m
        case None    => BlendMaterial.BlendEffects.None

      material match
        case m: BlendMaterial.BlendEffects =>
          l.withBlendMaterial(m.withAlpha(d))
        case _ => l
    }  // <-- Note the bracket type

@kitbellew kitbellew self-assigned this Mar 12, 2023
@jxnu-liguobin
Copy link
Author

This version works fine, all I've done is change the parenthesis to curly braces after SignalFunction:

But It's different from my code.

  implicit def map: Array[Any] => List[String] = a =>
    a.map ( ae => {
      ae match
        case s: String => s
        case _ => ae.toString
    }
    ).toList

There are two kinds of brackets. Removing any one will work normally.

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.

3 participants