Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8660

Unexpected MethodSelectionException with implicit null argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.0-alpha-2, 2.4.15, 2.5.0, 4.0.13
    • None
    • None

    Description

      class OnlySingle {
          def foo(a) { "single param: $a" }
      }
      
      println new OnlySingle().foo()
      // as expected: 'single param: null'
      
      
      class OnlyVararg {
          def foo(a, ... b) { "vararg param: $a, $b" }
      }
      
      println new OnlyVararg().foo()
      // as expected: 'MME: No signature of method: OnlyVararg.foo() is applicable for argument types: () values: []'
      
      class Both {
          def foo(a) { "single param: $a" }
          def foo(a, ... b) { "vararg param: $a, $b" }
      }
      
      println new Both().foo()
      // unexpected:
      // MethodSelectionException: Could not find which method foo() to invoke from this list:
      //  public java.lang.Object Both#foo(java.lang.Object)
      //  public transient java.lang.Object Both#foo(java.lang.Object, [Ljava.lang.Object;)
      

      If the exception is expected then OnlyVararg case should work too.
      If the exception is unexpected then Both#foo(Object) should be selected.

      Attachments

        Activity

          People

            Unassigned Unassigned
            daniilo Daniil Ovchinnikov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: