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

fix trait private method consistency

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-3
    • Compiler

    Description

      It seems that private in a trait is akin to protected in a class. For example a class that implements a trait may access private fields (through namespace syntax) and properties and call private static methods. And it may use Type.super.method() to disambiguate methods if necessary. Why, however, can a class that implements a trait not call private instance methods? This is not really covered in the language specification.

      trait T {
          private void privit() {
              println 'private'
          }
          public void publik() {
              println 'public'
          }
      }
      
      class C implements T {
          def m() {
              publik()
              privit()
          }
      }
      
      new C().m()
      

      This fails with missing method. But if static modifier is added to privit, it succeeds.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: