Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0, Scala 2.9.1
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      ==========================================================================================
      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)

        Activity

        Hide
        Seth Tisue added a comment -

        Should work if you change "trait Foo" to "class Foo".

        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.

        Show
        Seth Tisue added a comment - Should work if you change "trait Foo" to "class Foo". 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.
        Hide
        Paul Phillips added a comment -

        Thank you for saving me the trouble of figuring out/remembering that – I'm reopening because I can recognize the attempt and issue a warning.

        Show
        Paul Phillips added a comment - Thank you for saving me the trouble of figuring out/remembering that – I'm reopening because I can recognize the attempt and issue a warning.
        Hide
        Heiko Seeberger added a comment -

        Seth: Thanks for the explanation. Now that I know it it's obvious
        Paul: A warning would be great.

        Show
        Heiko Seeberger added a comment - Seth: Thanks for the explanation. Now that I know it it's obvious Paul: A warning would be great.
        Hide
        Commit Message Bot added a comment -

        (extempore in r25427) Working on jar creation infrastructure. Now if -d foo.jar is used for
        output generation (but only then, since otherwise we're not creating the jar):

        1) -Xmain-class foo.Bar will give the jar a Main-Class of foo.Bar
        2) Alternatively, if there is only one runnable program, that will be the Main-Class
        3) Always, the jar's manifest will have an entry for Scala-Compiler-Version.

        Not very relatedly, a warning is now issued when a module has a main method but
        a runnable program will not be generated. Closes SI-4861.

        This represents an opening step toward automatically recognizing mismatched
        bytecode situations: coarse, but useful and safe. Review by mirco.

        Show
        Commit Message Bot added a comment - (extempore in r25427 ) Working on jar creation infrastructure. Now if -d foo.jar is used for output generation (but only then, since otherwise we're not creating the jar): 1) -Xmain-class foo.Bar will give the jar a Main-Class of foo.Bar 2) Alternatively, if there is only one runnable program, that will be the Main-Class 3) Always, the jar's manifest will have an entry for Scala-Compiler-Version. Not very relatedly, a warning is now issued when a module has a main method but a runnable program will not be generated. Closes SI-4861 . This represents an opening step toward automatically recognizing mismatched bytecode situations: coarse, but useful and safe. Review by mirco.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Heiko Seeberger
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development