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

Erroneous method pointer expressions pass STC

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7
    • 3.0.14, 4.0.7
    • Static Type Checker
    • None

    Description

      Method pointer expressions are not type checked (with STC enabled). The following example should not compile for a number of reasons:

      @groovy.transform.TypeChecked
      void test() {
        def x = 'abc'.&bar //bar is not a String method
        x() // groovy.lang.MissingMethodException
        x = String.&length //length is a non-static method
        x() // java.lang.IllegalArgumentException: object is not an instance of declaring class
        x = String.&size //size is a non-static extension method
        x() // java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
      }
      test()
      

      Attachments

        Activity

          People

            emilles Eric Milles
            shils Shil Sinha
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: