Skip to content

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

Closed
@scalway

Description

@scalway

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions