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

Wrong type is inferred when involving a bounded type parameter in a parameterized method call

    XMLWordPrintableJSON

Details

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

    Description

      I have the following program

      class A<T> {
        T m() {
          return null;
        }
      }
      
      class B {
        B(byte x) {}
      }
      
      class C<T> {
        T x;
      
        C(T x) {
          this.x = x;
        }
      }
      
      class Test {
        <T extends A<Byte>> void test() {
          C<T> a = new C<T>(null);
          T x = a.x;
          new B(x.m()); // should type check
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 23: [Static type checking] - Cannot find matching method B#<init>(java.lang.Object). Please check if the declared type is correct and if the method exists.
       @ line 23, column 5.
             new B(x.m());
             ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Tested against master (commit: ee12bb52381e8f0583c61fc25d43de1f55b80a87)

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: