Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-7767

Single-parameter method chosen zero parameters passed

Agile BoardAttach filesAttach ScreenshotAdd voteVotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.6
    • None
    • None
    • None

    Description

      When there is a single variant of a given method name, and that method has a single parameter, then calls to that method with zero arguments will result in a call to the method with a value of null, even though the no argument is present in the actual method call. This is surprising and leads to silent errors. Instead, I would expect groovy to throw an error saying that no matching method could be found.

      Example:

      new A()
      
      class A {
      
          A(){
              m()
          }
      
          void m(String param){
              println "param: $param"
          }
      }
      

      Running the code above yields:

      param: null
      

      But I would expect it to yield something like:

      Caught: groovy.lang.MissingMethodException: No signature of method: A.m() is applicable for argument types: () values: []
      Possible solutions: m(java.lang.String), is(java.lang.Object), dump(), any(), any(groovy.lang.Closure), use([Ljava.lang.Object;)
      groovy.lang.MissingMethodException: No signature of method: A.m() is applicable for argument types: () values: []
      Possible solutions: m(java.lang.String), is(java.lang.Object), dump(), any(), any(groovy.lang.Closure), use([Ljava.lang.Object;)
              at A.<init>(testClass2.groovy:8)
              at testClass2.run(testClass2.groovy:3)
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            gubespam@gmail.com Mike Martin

            Dates

              Created:
              Updated:

              Slack

                Issue deployment