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

@CompileStatic doesn't support interfaces extending other interfaces

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc-4
    • 2.0.1
    • None
    • Windows 7 x64, Java 7

    Description

      [Major is the default priority, sorry if I'm supposed to assign to another]
      This code fails during static type checking:

      interface A {
          String getName();
      }
      
      interface B extends A {
          void foo();
      }
      
      @groovy.transform.CompileStatic
      class C {
          String name
          void bar(B b)
          {
              b.foo()
              name = b.name
          }
      }
      new C()
      

      With this error:

      [Static type checking] - No such property: name for class: B
      

      Changing the code to use getName() works, as does casting b to A.

      I also encountered a related issue, in which the getName() workaround fails:

      interface A {
          String getName();
      }
      
      interface A2 {
          String getName();
      }
      
      interface B extends A,A2 {
          void foo();
      }
      
      @groovy.transform.CompileStatic
      class C {
          String name
          void bar(B c)
          {
              c.foo()
              name = c.getName()
          }
      }
      new C()
      

      The casting workaround still works, but otherwise the error given is:

      [Static type checking] - Reference to method is ambiguous. Cannot choose between [MethodNode@1813166140[java.lang.String getName()], MethodNode@877270685[java.lang.String getName()]]
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            melix Cédric Champeau
            scoreunder Charles Daffern
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment