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

STC fails to instantiate type variable when using diamond operator

    XMLWordPrintableJSON

Details

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

    Description

      I have the following program

      class A<T extends Number> {
        A(String x) {}
      }
      
      
      class B {
        void m(A<Integer> x) {}
      }
      
      
      class Test {
        void test() {
          B x = new B();
          x.m(new A<>(""));
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 14: [Static type checking] - Cannot call B#m(A<java.lang.Integer>) with arguments [A<# extends java.lang.Number>]
       @ line 14, column 5.
             x.m(new A<>(""));
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully

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

      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: