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

STC: parameterized and bounded return value for java class property

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.11, 2.5.18, 4.0.4
    • 2.5.19, 3.0.13, 4.0.6
    • Static Type Checker
    • None

    Description

      Given:

      • A Java class having a method returning a generic Collection,
      • A groovy script compiled with "CompileStatic" and using the method of the JavaClass

      Then the type of the element of the collection is not correctly inferred.

      Example:

      public class Bridge { // java
          
          public <T extends File> Collection<T> getFiles() {
              return null;
          }
      }
      

      and the following script:

      @groovy.transform.CompileStatic
      def cst() {
          new Bridge().files.collect { it.name }
      }
      

      the compilation fails with the error:

      [Static type checking] - No such property: name for class: java.lang.Object
      

      Note:

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              j3rem1e J. Brébec
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: