Skip to content

-rewrite -indent doesn't add colons where required #8982

Closed
@eloots

Description

@eloots

Minimized code

Source file Foo.scala:

object Foo {
  def bar(x: Int): Unit = {
    println(x)
  }
}

class Baz(n: Int) {
  def printRepeat(repeat: Int) = {
    for {
      x <- 1 to repeat
    } println(s"$x - ${n * x}")
  }
}

Steps

  • run dotc -new-syntax -rewrite Foo.scala: produces a correctly rewritten source file using the new control syntax
  • run dotc -indent -rewrite Foo.scala produces a rewritten source file the has syntax errors (missing ':')

Output

The incorrect output:

object Foo
  def bar(x: Int): Unit =
    println(x)

class Baz(n: Int)
  def printRepeat(repeat: Int) =
    for
      x <- 1 to repeat
    do println(s"$x - ${n * x}")

Compiling this file produces the following errors:

$ dotc src/main/scala/coderewrite/Foo.scala
-- Warning: src/main/scala/coderewrite/Foo.scala:4:2 ---------------------------
4 |  def bar(x: Int): Unit =
  |  ^
  |  Line is indented too far to the right, or a `{` or `:` is missing
-- Warning: src/main/scala/coderewrite/Foo.scala:8:2 ---------------------------
8 |  def printRepeat(repeat: Int) =
  |  ^
  |  Line is indented too far to the right, or a `{` or `:` is missing
-- [E006] Not Found Error: src/main/scala/coderewrite/Foo.scala:11:24 ----------
11 |    do println(s"$x - ${n * x}")
   |                        ^
   |                        Not found: n

longer explanation available when compiling with `-explain`
2 warnings found
1 error found

Expectation

This is what it should be:

object Foo:
  def bar(x: Int): Unit =
    println(x)

class Baz(n: Int):
  def printRepeat(repeat: Int) =
    for
      x <- 1 to repeat
    do println(s"$x - ${n * x}")

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions