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

Cannot resolve type in the presence of use-site contravariance

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

       

      class Main {
        static final Bar<? super Short> bar = new Bar<Short>((Short) -94)
        static final short foo = Main.bar.x
      }
      
      class Bar<P> {
        public final P x
        public Bar(P x) { 
          this.x = x 
        }
      }
      

       

      Actual Behavior

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

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 5: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type short
      @ line 5, column 28.
      static final short foo = Main.bar.x
      ^
      1 error
      

      Expected Behavior

      Compile successfully.

      Comment

      Note that the equivalent Java program is accepted by javac.

      Tested against 4.0.3 and master (commit: 2e82c9f5bd6201ed4724b26714275f4cef9df6e8).

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: