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
Main class with companion cannot be run #4861
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4861?orig=1 |
@SethTisue said: From Java, a Scala trait is an interface, not a class, and interfaces can't have static methods such as "main". So this is unfixable. |
@paulp said: |
@hseeberger said: |
Commit Message Bot (anonymous) said:
Not very relatedly, a warning is now issued when a module has a main method but This represents an opening step toward automatically recognizing mismatched |
==========================================================================================
This is a bug, affected versions (at least) 2.9.0.1, 2.9.1.RC1 and 2.10 (a recent nightly)
This code compiles:
object Foo {
def main(args: Array[String]): Unit = {
println("Foo")
}
}
trait Foo
But it won't run:
java.lang.NoSuchMethodException: Foo.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1605)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:74)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
The text was updated successfully, but these errors were encountered: