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

Inherited methods with default parameters cause cause static compilation to fail

    XMLWordPrintableJSON

Details

    Description

      Given a super type with a method that has a default argument:

      @CompileStatic
      class SuperType {
      	void sample(String string, Integer arg=0) {}
      }
      

      And a subclass that extends the method, but omits the optional parameters:

      @CompileStatic
      class SubType extends SuperType {
      	@Override
      	void sample(String string) {}
      }
      

      Static type checking fails to pick which method to call in the following code:

      @CompileStatic
      class BrokenMethods {
      	public static void main(String[] args) {
      		new SubType().sample('hi')
      	}
      }
      

      The error message is:

      Reference to method is ambiguous. Cannot choose between [void codes.nom.broken.SubType#sample(java.lang.String), void codes.nom.broken.SubType#sample(java.lang.String)]
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            nathanwharvey Nathan Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: