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

STC fails to infer dependent type variable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.11, 4.0.3
    • Static Type Checker
    • None

    Description

      I have the following program

      class A<T1, T2 extends T1> {
        T1 f;
      
        A(T1 f) {
          this.f = f;
        }
        T2 foo() { return null; }
      }
      
      class Test {
        void test() {
          Integer x = 1;
          var y = new A<>(x).foo();
          Integer z = y;
        }
        
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 14: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Integer
       @ line 14, column 17.
             Integer z = y;
                         ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Note that the program above compiles as expected in javac.

      Tested against master (https://github.com/apache/groovy/commit/cee45d768bb65d1254a61a6dd4ce3c6a1f2ee3ca)

      Attachments

        1. screenshot-1.png
          27 kB
          Eric Milles

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: