The following style if/else statements are failing to compile on Dotty version 0.19.0-RC1
object Main {
def main(args: Array[String]): Unit = {
if (args.length > 0)
{
println(args)
} else {
println("Hello world!")
}
}
}
This should compile as it does in Scala 2.12
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.
This should not compile as as the indentation is incorrect, but it should have a better error message.
“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?
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.
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...
Note that you can turn off the indentation checks by adding -noindent to your scalacOptions.
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.
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: https://github.com/scalameta/scalafmt/issues/1509
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.
The issue here does have a straightforward fix, after all.
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.
Most helpful comment
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...