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

Cannot find matching method when trait that implements another trait is compiled statically

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

Details

    Description

      I have a trait that implements another trait, and when i try to statically compile it with groovy 3.0.12, it throws the following error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      B.groovy: 12: [Static type checking] - Cannot find matching method <UnionType:test.T+test.B>#methodA(). Please check if the declared type is correct and if the method exists.
       @ line 12, column 3.
                      methodA()
           ^
      
      1 error
      

      test case files attached. compilation:

      JAVA_HOME=/groovy-test/jdk8u275-b01 /groovy-test/groovy-3.0.12/bin/groovyc -classpath /groovy-test/src B.groovy
      

      all works good with 2.5.14

      when I add A into SelfType in B (so that it looks like @SelfType([T,A]), all compiles ok with 3.0.12 too.

      question: can adding A into SelfType be considered a safe workaround, provided that no class implementing B ever directly implements A?

      @groovy.transform.TypeChecked
      class Groovy10767 {
        trait A {
          void methodA() {
          }
        }
        @groovy.transform.SelfType(T)
        trait B implements A {
          void methodB() {
            methodA() // Cannot find matching method <UnionType:T+B>#methodA()
          }
        }
        static class C implements B {
          void method() {
            methodA()
            methodB()
          }
        }
        static class T {
          void methodT() {
          }
        }
      }
      

      Attachments

        Issue Links

        Activity

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

          People

            emilles Eric Milles
            Kachanovskiy Sergey Kachanovskiy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment