groovy
  1. groovy
  2. GROOVY-5439

error: incompatible types on Java stubs returning generics

    Details

    • Number of attachments :
      0

      Description

      The following class definition fails to compile the Java stubs:

      class GenericReturn {
          public <T extends List> T foo() {
              null
          }
      }
      

      Error:

      tmp/groovy-java-stubs/GenericReturn.java:16: error: incompatible types
      public <T extends java.util.List> T foo() { return (java.util.List)null;}
                                                         ^
        required: T
        found:    List
        where T is a type-variable:
          T extends List declared in method <T>foo()
      
      

      It compiles with no errors on 2.0-beta-2 and 1.8.6

        Activity

        Hide
        Alex Fulton added a comment - - edited

        I am also getting this error on 1.8.7.

        This code:

        class Schedule<T extends ScheduleItem> extends HashSet<T> {
            (...)
            T getCurrentItem() {
                (...)
            }
        }
        

        Gives the error:

        [ERROR] [...]\groovy-stubs\main\nz\ac\auckland\digitizer\scheduler\Schedule.java:[26,50] error: incompatible types
        [ERROR] required: T
        [ERROR] found:    ScheduleItem
        [ERROR] where T is a type-variable:
        [ERROR] T extends ScheduleItem declared in class Schedule
        

        The offending line in the stub:

        public  T getCurrentItem() { return (nz.ac.auckland.digitizer.scheduler.ScheduleItem)null;}
        

        Doing a clean and rebuild in 1.8.6 with the same sources works fine.

        Show
        Alex Fulton added a comment - - edited I am also getting this error on 1.8.7. This code: class Schedule<T extends ScheduleItem> extends HashSet<T> { (...) T getCurrentItem() { (...) } } Gives the error: [ERROR] [...]\groovy-stubs\main\nz\ac\auckland\digitizer\scheduler\Schedule.java:[26,50] error: incompatible types [ERROR] required: T [ERROR] found: ScheduleItem [ERROR] where T is a type-variable: [ERROR] T extends ScheduleItem declared in class Schedule The offending line in the stub: public T getCurrentItem() { return (nz.ac.auckland.digitizer.scheduler.ScheduleItem)null;} Doing a clean and rebuild in 1.8.6 with the same sources works fine.
        Hide
        Alex Fulton added a comment -

        (also, the component for this issue should be stub generator, not compiler)

        Show
        Alex Fulton added a comment - (also, the component for this issue should be stub generator, not compiler)
        Guillaume Laforge made changes -
        Field Original Value New Value
        Priority Major [ 3 ] Blocker [ 1 ]
        Component/s Stub generator / Joint compiler [ 14523 ]
        Component/s Compiler [ 13529 ]
        Hide
        Alex Fulton added a comment -

        Please note: the version field for this issue is misleading. This bug affects all versions of Groovy since 1.8.7, including 1.8.8 and 2.0.2. I am currently unable to upgrade to a newer version than 1.8.6 because my code will not compile in anything newer.

        Show
        Alex Fulton added a comment - Please note: the version field for this issue is misleading. This bug affects all versions of Groovy since 1.8.7, including 1.8.8 and 2.0.2. I am currently unable to upgrade to a newer version than 1.8.6 because my code will not compile in anything newer.
        Hide
        Guillaume Laforge added a comment -

        Covered also by GROOVY-5710 and GROVY-5630

        Show
        Guillaume Laforge added a comment - Covered also by GROOVY-5710 and GROVY-5630
        Guillaume Laforge made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Guillaume Laforge [ guillaume ]
        Fix Version/s 1.8.9 [ 18778 ]
        Fix Version/s 2.0.3 [ 18777 ]
        Fix Version/s 2.1.0 [ 18598 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Renato Garcia
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: