Groovy
  1. Groovy
  2. GROOVY-5439

error: incompatible types on Java stubs returning generics

    Details

      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

        Renato Garcia created issue -
        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 Delcroix made changes -
        Field Original Value New Value
        Component/s Stub generator / Joint compiler [ 14523 ]
        Priority Major [ 3 ] Blocker [ 1 ]
        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 Delcroix added a comment -

        Covered also by GROOVY-5710 and GROVY-5630

        Show
        Guillaume Delcroix added a comment - Covered also by GROOVY-5710 and GROVY-5630
        Guillaume Delcroix made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1.0 [ 18598 ]
        Assignee Guillaume Laforge [ guillaume ]
        Fix Version/s 2.0.3 [ 18777 ]
        Fix Version/s 1.8.9 [ 18778 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12734359 ] Default workflow, editable Closed status [ 12746075 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971789 ] Default workflow, editable Closed status [ 12979562 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        137d 13h 55m 1 Guillaume Delcroix 18/Sep/12 08:28
        Resolved Resolved Closed Closed
        3d 9h 30m 1 Paul King 21/Sep/12 17:58

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development