You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "João Nelas (Jira)" <ji...@apache.org> on 2021/06/18 14:11:00 UTC

[jira] [Created] (GROOVY-10144) Calling method on specific trait fails when on different files

João Nelas created GROOVY-10144:
-----------------------------------

             Summary: Calling method on specific trait fails when on different files
                 Key: GROOVY-10144
                 URL: https://issues.apache.org/jira/browse/GROOVY-10144
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 3.0.7
         Environment: macOS 10.15.7, groovy 3.0.7,  AdoptOpenJDK)(build 1.8.0_282-b08)
            Reporter: João Nelas


When calling a method on a specific trait, via the manual conflict resolution syntax, it fails with {{The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.}}.

T.groovy
{code:groovy}
trait T {
    void exec() {
        println("T - exec");
    }
}
{code}
A.groovy
{code:groovy}
class A implements T{
    void exec() {
        println("A - exec");
        T.super.exec();
    }
}
{code}
diff_files.groovy
{code:groovy}
import A;

new A().exec();
{code}
Running {{diff_files.groovy}} gives an error:
{noformat}
> groovy diff_files.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/Users/joao/tmp/groovy_trait/A.groovy: 6: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
 @ line 6, column 10.
           T.super.exec();
            ^

1 error
{noformat}
If everything is included on the same file
 onefile.groovy
{code:groovy}
trait T {
    void exec() {
        println("T - exec");
    }
}

class A implements T{
    void exec() {
        println("A - exec");
        T.super.exec();
    }
}

new A().exec();
{code}
everything works as expected:
{noformat}
>groovy onefile.groovy
A - exec
T - exec
{noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)