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

Calling method on specific trait fails when on different files

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.7
    • 4.0.0-rc-2
    • parser-antlr4
    • macOS 10.15.7, groovy 3.0.7, AdoptOpenJDK)(build 1.8.0_282-b08)

    Description

      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

      trait T {
          void exec() {
              println("T - exec");
          }
      }
      

      A.groovy

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

      diff_files.groovy

      import A;
      
      new A().exec();
      

      Running diff_files.groovy gives an error:

      > 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
      

      If everything is included on the same file
      onefile.groovy

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

      everything works as expected:

      >groovy onefile.groovy
      A - exec
      T - exec
      

      Attachments

        Activity

          People

            emilles Eric Milles
            adagios João Nelas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: