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

Class.&instanceMethod with incorrect first param

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0-beta-1
    • 3.0.0-beta-2
    • None
    • None

    Description

      In Groovy 3 we extended the method pointer to also work for a Class receiver and instance method. When used in this way, the method closure produced accepts an additional initial argument being the instance receiver. This works when supplied with a correct argument but gives an IllegalArgumentException instead of MissingMethodException when an illegal argument is supplied. E.g.:

      class Y {
        def m() {1}
      }
      
      ref = Y.&m
      assert ref(new Y()) == 1
      assert ref() == 1 // => java.lang.IllegalArgumentException: object is not an instance of declaring class [Should just be missing method exception?]
      assert ref(1) == 1 // => java.lang.IllegalArgumentException: object is not an instance of declaring class [Should just be missing method exception?]
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: