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

Type argument inference does not work in closure

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

      class Foo {}
      
      final class A<T extends Foo> {
        public T x;
        A(T x) {
          this.x = x;
        }
      }
      
      @groovy.transform.CompileStatic
      public class C<T extends Number> {
        public void foo(T args) {
          final A<Foo> x = new A<>(new Foo()); // compiles
          def closure = p -> {
              final A<Foo> y = new A<>(new Foo()); // does not compile
          }
        }
      }
      
      

      Actual Behavior

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

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Foo.groovy: 15: [Static type checking] - Cannot call A#<init>(T) with arguments [Foo]
       @ line 15, column 26.
                 final A<Foo> y = new A<>(new Foo()); 
                                  ^
      
      1 error
      
      

      Expected Behavior

      Compile successfully.

      Comment

      This should be a regression bug because it compiles with the 3.0.7 compiler and the 4.0.0-alpha-2.

      Affected Version

      This programs fails when compiled with the compiler from the master (commit: 5d2944523f198d96b6515e85a24d2b4e43ce665f).

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h