dotty-feature-requests icon indicating copy to clipboard operation
dotty-feature-requests copied to clipboard

Improvement to `@main` annotation

Open j-mie6 opened this issue 5 years ago • 0 comments

I really like the new @main annotation, but there is one thing that does slightly bother me about it: I can't provide defaults!

Previously, I could write something like this:

def main(args: Array[String]): Unit = if (args.length == 1) println(args.head) else println("default")

And I would have hoped that now I might write something like this:

@main def foo(msg: String = "default") = println(msg)

But this will result in Illegal Command Line: more arguments expected if you try and run it with no arguments. Could this be implemented as an extension of the current system?

j-mie6 avatar Sep 17 '19 11:09 j-mie6