Scala Programming Language
  1. Scala Programming Language
  2. SI-6896

Incorrect warning when object contains multiple main methods

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-RC5
    • Fix Version/s: Scala 2.10.1
    • Component/s: Misc Compiler
    • Environment:

      Mac OSX Snow Leopard
      Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-10M3909)
      Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

      Description

      When an object contains multiple methods named main, including one with a valid type signature for the "true" main method, the compiler issues a warning indicating that the object contains no such method.

      Here's an example:

      object TooManyMains {                                                                                                                       
        def main(args: Array[String]): Unit = {                                                                                                   
          println("Hello, World!")                                                                                                                
        }                                                                                                                                         
        def main(a: Int, b: Int) = ???                                                                                                            
        def main(s: String, n: String) = ???                                                                                                      
      }    
      
      scalac mains.scala
      mains.scala:1: warning: TooManyMains has a main method with parameter type Array[String], but TooManyMains will not be a runnable program.
        Reason: main method must have exact signature (Array[String])Unit
      object TooManyMains {
             ^
      one warning found
      

      However it will will run successfully:

      scala TooManyMains
      Hello, World!
      
      1. mains.scala
        0.2 kB
        Erik Engbrecht

        Issue Links

          Activity

          Show
          Paul Phillips added a comment - https://github.com/scala/scala/pull/1835
          Hide
          Jason Zaugg added a comment -

          This was merged in 2.10.1

          Show
          Jason Zaugg added a comment - This was merged in 2.10.1

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Erik Engbrecht
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development