scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

End on empty method returning Unit #12150

Closed nicolasstucki closed 3 years ago

nicolasstucki commented 3 years ago

Compiler version

3.0.0-RC2

Minimized code

def f: Unit =

end f

Output

2 |end f
  |^^^
  |postfix operator `f` needs to be enabled
  |by making the implicit value scala.language.postfixOps visible.
  |----
  |This can be achieved by adding the import clause 'import scala.language.postfixOps'
  |or by setting the compiler option -language:postfixOps.
  |See the Scaladoc for value scala.language.postfixOps for a discussion
  |why the feature needs to be explicitly enabled.

Expectation

Should compile or should have a better error message.

It feels like it should behave the same as

def f: Unit = {

}
nicolasstucki commented 3 years ago

I ended up in this situation when I did something like this.

def f: Unit =
-  val x = ...
-  g(x)
+  // val x = ...
+  // g(x)
end f

The code was much longer.