[ 
https://issues.apache.org/jira/browse/GROOVY-10767?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-10767:
---------------------------------
    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:
{code}
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
{code}

test case files attached. compilation:
{code}
JAVA_HOME=/groovy-test/jdk8u275-b01 /groovy-test/groovy-3.0.12/bin/groovyc 
-classpath /groovy-test/src B.groovy
{code}

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?

{code:groovy}
@groovy.transform.CompileStatic
class Groovy10765 {
  trait A {
    void methodA() {
    }
  }
  @groovy.transform.SelfType([A,T])
  trait B implements A {
    void methodB() {
      methodA()
    }
  }
  class C implements B {
    void method() {
      methodA()
      methodB()
    }
  }
  class T {
    void methodT() {
    }
  }
}
{code}

  was:
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:
{code}
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
{code}

test case files attached. compilation:
{code}
JAVA_HOME=/groovy-test/jdk8u275-b01 /groovy-test/groovy-3.0.12/bin/groovyc 
-classpath /groovy-test/src B.groovy
{code}

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?




> Cannot find matching method when trait that implements another trait is 
> compiled statically
> -------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10767
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10767
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 3.0.12
>            Reporter: Sergey Kachanovskiy
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: GROOVY-10767.tar.gz
>
>
> 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:
> {code}
> 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
> {code}
> test case files attached. compilation:
> {code}
> JAVA_HOME=/groovy-test/jdk8u275-b01 /groovy-test/groovy-3.0.12/bin/groovyc 
> -classpath /groovy-test/src B.groovy
> {code}
> 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?
> {code:groovy}
> @groovy.transform.CompileStatic
> class Groovy10765 {
>   trait A {
>     void methodA() {
>     }
>   }
>   @groovy.transform.SelfType([A,T])
>   trait B implements A {
>     void methodB() {
>       methodA()
>     }
>   }
>   class C implements B {
>     void method() {
>       methodA()
>       methodB()
>     }
>   }
>   class T {
>     void methodT() {
>     }
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to