Skip to content

Incorrect warning when object contains multiple main methods #6896

Closed

Description

@scabug

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!

Activity

  1. scabug commented on Dec 30, 2012

    @scabug
    Author

    Imported From: https://issues.scala-lang.org/browse/SI-6896?orig=1
    Reporter: @eengbrec
    Affected Versions: 2.10.0-RC5
    Attachments:

    • mains.scala (created on Dec 30, 2012 9:48:03 PM UTC, 171 bytes)
  2. scabug commented on Dec 31, 2012

    @scabug
    Author
  3. scabug commented on Jun 6, 2013

    @scabug
    Author

    @retronym said:
    This was merged in 2.10.1

  4. added this to the 2.10.1 milestone on Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions