Skip to content
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

Dotty fails to compile with } and else on the same line #7421

Closed
Mocuto opened this issue Oct 14, 2019 · 10 comments
Closed

Dotty fails to compile with } and else on the same line #7421

Mocuto opened this issue Oct 14, 2019 · 10 comments

Comments

@Mocuto
Copy link

Mocuto commented Oct 14, 2019

The following style if/else statements are failing to compile on Dotty version 0.19.0-RC1

minimized code

object Main {

  def main(args: Array[String]): Unit = {
    if (args.length > 0)
      {
        println(args)
      } else {
      println("Hello world!")
    }
  }
}

expectation

This should compile as it does in Scala 2.12

actual

This fails to compile:

[error] -- Error: D:\code\dotty-cont\dottyplayground\src\main\scala\Main.scala:7:8 -----
[error] 7 |      } else {                                                                                               [error]   |        ^^^^                                                                                                 [error]   |        end of statement expected but else found                                                             [error] -- [E040] Syntax Error: D:\code\dotty-cont\dottyplayground\src\main\scala\Main.scala:7:13
[error] 7 |      } else {                                                                                               [error]   |             ^                                                                                               [error]   |             ';' expected, but '{' found                                                                     [error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed Oct 13, 2019 9:12:30 PM

The workaround is simple but this behavior is unexpected.

@bishabosha
Copy link
Member

bishabosha commented Oct 14, 2019

This should not compile as as the indentation is incorrect, but it should have a better error message.

@Mocuto
Copy link
Author

Mocuto commented Oct 15, 2019

“The indentation is incorrect” this syntax compiles fine in Scala 2. Why should indentation be impacting compilation, I thought the new (controversial) Python style indentation is optional??

Why is Scala 3 introducing non-backwards compatible syntax changes and what is being gained in return?

@OlivierBlanvillain
Copy link
Contributor

This is a consequence of the new indentation syntax. Because both styles can be used within a single file, proper indentation is now also required for code that uses braces.

what is being gained in return?

I believe stricter rules could help beginners to learn how to properly indent their code.

@jducoeur
Copy link
Contributor

There's never been any sign of universal agreement about the meaning of "properly indent" in the Scala community -- that's why our linting tools are flexible.

Seriously -- this is a solution in search of a problem, and it's causing endless problems (and endless bikeshedding) as a result...

@smarter
Copy link
Member

smarter commented Oct 15, 2019

Note that you can turn off the indentation checks by adding -noindent to your scalacOptions.

@Mocuto
Copy link
Author

Mocuto commented Oct 15, 2019

The indentation checks should be off by default as this is an experimental feature, not a deprecation.

And about “properly indenting code”, that code indentation was actually produced by the version of ScalaFMT I was using. Whether that indentation is “proper” or not is entirely subjective.

If we’re interested in helping beginners, having Scala 2 code bases where indentation is not significant and Scala 3 code bases where indentation is significant (and causes compiler errors) will only confuse and annoy beginners.

Languages with preferred indentation styles like Java, JavaScript, even Python accomplish this through linters and auto formatters, not by breaking the language.

@smarter
Copy link
Member

smarter commented Oct 15, 2019

The indentation checks should be off by default as this is an experimental feature, not a deprecation.

Dotty is an experimental compiler, there's many experimental things in it, having them by default is a good way for people to actually experiment with them :).

that code indentation was actually produced by the version of ScalaFMT I was using.

There was a bug in scalafmt that got fixed recently: scalameta/scalafmt#1509

@Mocuto
Copy link
Author

Mocuto commented Oct 15, 2019

My final thoughts are this are that it’s untenable to market Dotty as Scala 3, as Odersky has in several blog posts, and then fall back on the claim that it’s actually an “experimental compiler” when regressions are introduced, particularly when the public plans are to finalize this within the next year.

When you commit Dotty to being Scala 3 developers will take that seriously, and the Dotty team needs to seriously weigh the expectations that come with that.

@odersky odersky reopened this Oct 15, 2019
@odersky
Copy link
Contributor

odersky commented Oct 15, 2019

The issue here does have a straightforward fix, after all.

@odersky
Copy link
Contributor

odersky commented Oct 15, 2019

We are not yet in feature freeze. Until we are, any expectations of stability are premature. The moment this changes is when the release is labelled Scala 3.0 M1, and not Dotty 0.19. So, if you want to try out Dotty now, enjoy the ride. If stability is a must for you, wait for 3.0 M1.

odersky added a commit that referenced this issue Oct 28, 2019
Fix #7421: Insert missing <outdent> tokens where a region ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants