Skip to content

Allow indentation inside (...) #8659

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

Merged
merged 3 commits into from
Apr 5, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 4, 2020

Change the rules so that indentation is recognized everywhere, and
not just at the toplevel and inside braces.

odersky added 2 commits April 4, 2020 13:20
Change the rules so that indentation is recognized everywhere, and
not just at the toplevel and insider parentheses.
@odersky odersky force-pushed the change-indent-parens branch from dfa68fb to ef0e7e0 Compare April 4, 2020 15:37
@odersky odersky changed the title Don't handle newlines if next token is set Allow indentation inside (...) Apr 4, 2020
@odersky odersky marked this pull request as ready for review April 4, 2020 15:40
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested passing for these

def foo(x: Int) =
  var x1 = x
  List(
      if x > 0
        true
      else
        false
      ,
  while x1 > 0 do
    x1 -= 1
    ,
    while
      x1 > 0
    do
      x1 -= 1
    ,
      try
        ???
      catch
      case err =>
      finally
        println("foo"),
            for
              i <- 1 to 10
            yield
              i * 2
    ,
    for _ <- 1 to 3 do
      for _ <- 3 to 6 do
        x1 += 1
  )

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: it is surprising that these compile (if your mental model was indentation syntax was about column alignment, and not simply that braces are now optional)

  def foo(x: Int) =
    var x1 = x
    List(
while x1 > 0 do
  x1 -= 1
)
  def foo(x: Int) =
    var x1 = x
    while x1 > 0 do
x1 -= 1
  package example

        class Foo:
    def foo(x: Int) =
      var x1 = x
      while x1 > 0 do
x1 -= 1

@odersky
Copy link
Contributor Author

odersky commented Apr 5, 2020

@bishabosha Why should these examples not pass? Note that the while-do is followed by a single statement. So that compiles even without implied braces.

@bishabosha
Copy link
Member

@odersky Those last examples I didn't compare to the previous dotty release as I was so surprised, so yes I agree now that those behave as expected.

So I suppose the feature really is optional braces, and the realm of aesthetic code alignment is left to linters

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 this pull request may close these issues.

2 participants