Skip to content

-rewrite -no-indent breaks code with Optional Braces for Method Arguments #17399

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

Closed
scalway opened this issue May 3, 2023 · 2 comments · Fixed by #17410
Closed

-rewrite -no-indent breaks code with Optional Braces for Method Arguments #17399

scalway opened this issue May 3, 2023 · 2 comments · Fixed by #17410

Comments

@scalway
Copy link

scalway commented May 3, 2023

Compiler version

3.3.0-RC5

Minimized code

//  BadRewrite.scala

//> using scala "3.3.0-RC5"
//> using options "-rewrite", "-no-indent"

def test[T](body:T):T = body

object Test:
  test:
    println("test 1")

Output

when we call scala-cli compile BadRewrite.scala our file is rewriten to:

//Result clearly incorrect
//> using scala "3.3.0-RC5"
//> using options "-rewrite", "-no-indent"

def test[T](name:String)(body:T):T = body

object Test {
  test {
    println("test 1")
}

and it clearly misses single bracket. It happens only when you use "optional braces for method arguments" as last thing in block.

If we add anything after call on the same level (here object Test) it will produce proper result:

object Test:
  test:
    println("test 1")
  val dummy = 2 //even comment is enough!!

translates to

//Result as expected 
object Test {
  test {
    println("test 1")
  }
  val dummy = 2 //even comment is enough!!
}

Weird Behavior of End Marker

object Test:
  test:
    println("test 1")
end Test

translates to:

object Test {
  test {
    println("test 1")
} // end Test

but with extra \n:

object Test:
  test:
    println("test 1")

end Test

translates to:

object Test {
  test {
    println("test 1")
}

end Test
@scalway scalway added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 3, 2023
@som-snytt
Copy link
Contributor

Presumptive duplicate of #17187 which was just fixed.

@som-snytt
Copy link
Contributor

som-snytt commented May 3, 2023

Confirmed. Before I updated my repo just now:

➜  snips diff bad-rewr*a
4,5c4,5
< object Test {
<   test {
---
> object Test:
>   test:
7d6
< }

After:

➜  snips diff bad-rewr*a
4,5c4,5
< object Test {
<   test {
---
> object Test:
>   test:
7,8d6
<   }
< }

Someday, I'll use scala-cli to test nightlies, instead of downgrading from JDK 20 in order to build dotty...

ckipp01 added a commit to ckipp01/dotty that referenced this issue May 4, 2023
This adds in a test to ensure that the issue reported in scala#17399 is
indeed fixed with scala#12954. This case is a bit different, so best to also
just have it covered with a test.

Closes scala#17399
@mbovel mbovel added area:rewriting tool and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 4, 2023
@mbovel mbovel closed this as completed May 4, 2023
ckipp01 added a commit that referenced this issue May 4, 2023
This adds in a test to ensure that the issue reported in #17399 is
indeed fixed with #12954. This case is a bit different, so best to also
just have it covered with a test.

Closes #17399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants