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

Invalid stub generated for a constructor using a generic bounded parameter

    XMLWordPrintableJSON

Details

    Description

      Given the 2 following classes:

      class A<T extends Number> {
          final T value
      
          A(T value) {
              this.value = value
          }
      }
      

      and

      class B extends A<Integer> {
          B(Integer value) {
              super(value)
          }
      }
      

      the generated stub for B does not compile, as the constructor parameter is cast to the bounded type instead of the actual type:

      public class B
        extends A<java.lang.Integer> {
      ;
      public B
      (java.lang.Integer value) {
      super ((java.lang.Number)null);
      }
      // ...
      }
      

      The error returned by the compiler is:

      target/generated-sources/groovy-stubs/main/B.java:[13,1] constructor A in class A<T> cannot be applied to given types;
        required: java.lang.Integer
        found: java.lang.Number
        reason: actual argument java.lang.Number cannot be converted to java.lang.Integer by method invocation conversion
      

      I've attached a test case, which is also available on Github.

      Attachments

        1. generic-superclass-stub.tar.gz
          5 kB
          Frank Pavageau

        Activity

          People

            emilles Eric Milles
            fpavageau Frank Pavageau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m