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

Cannot infer correct type argument when using subtyping

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.8, 4.0.0-alpha-3
    • Component/s: None
    • Labels:
      None

      Description

      I have the following Groovy program.

      @groovy.transform.CompileStatic
      public class Main {
        public static void main(String[] args) {
          Foo foo = new Bar()
          def x = new A<>(foo)
          bar(x)
        }
      
        public static void bar(A<Foo> f) {}
      }
      
      class A<T> {
        T f;
        public A(T f) {
          this.f = f;
        }
      }
      
      class Foo {}
      class Bar extends Foo {}
      

      Actual Behavior

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

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 6: [Static type checking] - Cannot call Main#bar(A <Foo>) with arguments [A <Bar>]
       @ line 6, column 5.
             bar(x)
             ^
      
      1 error
      
      

      Expected Behavior

      Compile successfully.

      Affected Version

      This should be a regression. The program compiles with 3.0.7 and 4.0.0-alpha-2, but fails with the compiler from Master (commit: e69c874e1a6a3cdeb236bad6a6faa061a30c88ca).

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              schaliasos Stefanos Chaliasos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 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