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

PositionExceptionImpl complaining about expected ) when encountering valid <- in for comprehension #3911

Closed
mdedetrich opened this issue Apr 7, 2024 · 2 comments · Fixed by scalameta/scalameta#3688

Comments

@mdedetrich
Copy link
Contributor

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = 3.8.1
runner.dialect = scala212source3
maxColumn = 120
project.git = true

# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings.style = Asterisk
literals.hexDigits = upper
project.layout = StandardConvention

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt

Steps

Given code like this:

// #slickQueryImplicitJoin
val slick2 =
  // #slickQueryImplicitJoin
  // or equivalent for-expression:
  (for (
    p <- people
    a <- addresses if p.addressId === a.id
  ) yield (p.name, a.city)).result
// #slickQueryImplicitJoin
val ((sqlRes, slickRes), slick2Res) = Await.result(db.run(sql zip slick zip slick2), Duration.Inf)
assert(sqlRes == slickRes)
assert(slickRes == slick2Res)
assert(sqlRes.size > 0)

Problem

Scalafmt fails with

org.scalafmt.dynamic.exceptions.PositionExceptionImpl: /Users/mdedetrich/github/slick/doc/code/SqlToSlick.scala:287: error: [dialect scala3] `)` expected but `<-` found
            p <- people58 source files formatted
              ^: /Users/mdedetrich/github/slick/doc/code/SqlToSlick.scala

Expectation

I would expect scalafmt to not fail

Workaround

Turning the formatting off with // format: off works

Notes

Changing the dialect with different dialects using fileOverride { "glob:**/doc/**.scala" = scala212 } doesn't have any effect, so it seems unrelated to dialect.

See original PR at slick/slick#2909

@kitbellew
Copy link
Collaborator

@mdedetrich where is this syntax defined as valid (i.e., specifying multiple enumerators without semicolons within parens)? i tried it in scastie, and the compiler complains: https://scastie.scala-lang.org/BzMsTlvTQsOIY6dG3ITRSA

my earlier fix for your reported problem is causing a regression: scalameta/scalameta#3715.

@kitbellew
Copy link
Collaborator

ok, looks like this is a matter of incorrect bug report :(

your code DOES have the semicolon: https://github.com/slick/slick/blob/main/doc/code/SqlToSlick.scala#L280

@kitbellew kitbellew reopened this May 18, 2024
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