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

Wrong 'Inconvertible types' error on casting interface

    Details

      Description

      import groovy.transform.CompileStatic
      
      interface A1{}
      interface A2 extends A1{}
              
      class C1 implements A1{}
      class C2 extends C1 implements A2 {}
              
      @CompileStatic
      def m(A2 a2) {
             C1 c1 = (C1) a2 // There is error here now: Inconvertible types: cannot cast A2 to C1
      }
      

      JLS handle this situation in 5.1.6.1 :
      A narrowing reference conversion exists from reference type S to reference type T
      if ...... - S is an interface type, T is a class type, and T does not name a final class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                daniel_sun Daniel Sun
                Reporter:
                Alexey Afanasiev Alexey Afanasiev
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: