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

STC: cannot combine use-variance with bounded polymorphism

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

      @groovy.transform.TypeChecked
      class Test {
        public void m() {
          Foo<? super C> x = new Foo<B>();
        }
      
      }
      
      class A {}
      class B extends A {}
      class C extends B {}
      
      class Foo<T extends A> {
      }
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Test.groovy: 4: The type ? is not a valid substitute for the bounded parameter <T extends A>
       @ line 4, column 9.
             Foo<? super C> x = new Foo<B>();
                 ^
      
      1 error
      

      Expected Behavior

      Compile successfully.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              schaliasos Stefanos Chaliasos
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: