Skip to content

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

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
eloots opened this issue May 14, 2020 · 0 comments · Fixed by #9002
Closed

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

eloots opened this issue May 14, 2020 · 0 comments · Fixed by #9002
Assignees

Comments

@eloots
Copy link
Contributor

eloots commented May 14, 2020

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}")
odersky added a commit to dotty-staging/dotty that referenced this issue May 19, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue May 19, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 25, 2020
liufengyun added a commit that referenced this issue May 25, 2020
Fix #8982: Insert colons when rewriting classes to indentation syntax
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 25, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 28, 2020
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