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

Ambiguous warning when main result is not Unit #7448

Closed
scabug opened this issue May 3, 2013 · 5 comments · Fixed by scala/scala#9576
Closed

Ambiguous warning when main result is not Unit #7448

scabug opened this issue May 3, 2013 · 5 comments · Fixed by scala/scala#9576
Assignees

Comments

@scabug
Copy link

scabug commented May 3, 2013

Warning about def main(args: Array[String]) = ??? is ambiguous.

This is a trivial matter, yet it burned a minute to see whether the test that provokes it is actually run. (I think all the runners use ScalaClassLoader.run.)

apm@mara:~/projects/snytt/test$ skalac -d foo files/run/repl-backticks.scala
files/run/repl-backticks.scala:3: warning: Test has a main method with parameter type Array[String], but Test will not be a runnable program.
  Reason: main method must have exact signature (Array[String])Unit
object Test {
       ^
one warning found
apm@mara:~/projects/snytt/test$ ls foo
Test.class  Test$.class
apm@mara:~/projects/snytt/test$ skala -cp foo Test
import java.lang.Thread.`yield`
import scala.`package`.Throwable
apm@mara:~/projects/snytt/test$ 
@scabug
Copy link
Author

scabug commented May 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7448?orig=1
Reporter: @som-snytt
Affected Versions: 2.11.0-M2
See #6896

@scabug
Copy link
Author

scabug commented May 7, 2013

Tanin Na Nakorn (tanin) said:
Did you use def main(args: Array[String]) = {...}?

You should use def main(args: Array[String]) {...} (no equal sign)

@scabug
Copy link
Author

scabug commented May 7, 2013

@som-snytt said:
To clarify, existing tests use the incorrect idiom.

The warning should say, Scala is catholic in its notion of main, but other launchers may be unforgiving.

It's possible that Scala is an Episcopalian, that is, a lover of ceremonious incantations, but also quite capable of doing without the trappings and accepting whatever is practical.

@scabug
Copy link
Author

scabug commented May 9, 2013

@som-snytt said:
Similarly, for nested objects, where there is no expectation:

-t1005.scala:6: warning: FromMono has a main method with parameter type Array[String], but Test.FromMono will not be a runnable program.
-  Reason: main method must have exact signature (Array[String])Unit
-  object FromMono{

Though if the signature is exactly that, it could warn for the reason that the object is not top-level. Or warn under -Xlint or -Xnoob.

@jeffrey-aguilera
Copy link

It sure would be nice for main to return Nothing ... like sys.exit.

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 a pull request may close this issue.

4 participants