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

Uncaught Missing token index error since upgrade to scalafmt-core 3.5.0 #3185

Closed
shonfeder opened this issue Apr 11, 2022 · 1 comment · Fixed by #3186
Closed

Uncaught Missing token index error since upgrade to scalafmt-core 3.5.0 #3185

shonfeder opened this issue Apr 11, 2022 · 1 comment · Fixed by #3186

Comments

@shonfeder
Copy link

shonfeder commented Apr 11, 2022

We've been experiencing an uncaught exception in runs of scalafmtCheckAll when trying to upgrade scalafmt to version 3.5.0. I was not able to reproduce using the scalafmt CLI alone, so am reporting the issue to the sbt plugin repo, as instructed in the scalafmt issue template.

Synopsis

We hit the following error:

> scalafmtCheckAll
[info] scalafmt: Checking 1 Scala sources (/home/sf/scratch/scalafmterr)...
[error] stack trace is suppressed; run last Compile / scalafmtCheck for the full output
[error] (Compile / scalafmtCheck) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: Missing token index [63:64]: `
[error] ` [/home/sf/scratch/scalafmterr/src/main/scala/example/scalafmterr.scala]
[error] Total time: 0 s, completed Apr 11, 2022, 1:35:10 PM

With the following configs:

.scalafmt.conf:

version = "3.5.1"
runner.dialect = scala212
preset = Scala.js

build.sbt:

ThisBuild / scalaVersion := "2.12.15"

package/plugins.sbt:

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")

With the source file ./src/main/scala/example/scalafmterr.scala with the following content:

package example

trait ExampleTrait {

  def foo(a: Int, b: Int)
  def bar(a: Int)
}

Full reproduction example

See https://github.com/shonfeder/scalafmt-missing-token-err-mwe

References

You can see these failures in the context of our CLI here:

Workaround

A workaround is just to annotate the methods' return types:

package example

trait ExampleTrait {

  def foo(a: Int, b: Int): Unit
  def bar(a: Int): Unit
}
shonfeder referenced this issue in scala-steward/apalache Apr 11, 2022
This is both a workaround for
https://github.com/scalameta/sbt-scalafmt/issues/222 and, afaik, in
keeping with preferred Scala style guidelines.
@kitbellew kitbellew transferred this issue from scalameta/sbt-scalafmt Apr 17, 2022
@shonfeder
Copy link
Author

shonfeder commented Apr 18, 2022

Thanks for the quick fix!

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