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

Problem With Private Methods In A Trait

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.3.9, 2.4.0-rc-1
    • None
    • None

    Description

      The attached traitissue.zip contains the following code:

      src/main/groovy/demo/SomeTrait.groovy
      package demo
      
      trait SomeTrait {
      
          static getSomeValue() {
              someHelperMethod()
          }
      
          private static someHelperMethod() {
              42
          }
      }
      
      src/test/groovy/demo/SomeTraitSpec.groovy
      package demo
      
      import spock.lang.Specification
      
      class SomeTraitSpec extends Specification {
      
          void 'test static method'() {
              expect:
              SomeClass.getSomeValue() == 42
      
          }
      }
      
      class SomeClass implements SomeTrait {}
      

      Using the current 2.4.0-SNAPSHOT that test fails with the following:

      groovy.lang.MissingMethodException: No signature of method: static demo.SomeClass.someHelperMethod() is applicable for argument types: () values: []
          at demo.SomeTrait$Trait$Helper.getSomeValue(SomeTrait.groovy:6)
          at demo.SomeTraitSpec.test static method(SomeTraitSpec.groovy:9)
      

      If the private method in SomeTrait is promoted to public, the test passes. If build.gradle is edited to use either Groovy 2.3.7 or 2.3.8 or 2.4.0-beta-4 the test passes.

      Attachments

        1. traitissue.zip
          50 kB
          Jeff Brown

        Issue Links

          Activity

            People

              melix Cédric Champeau
              brownj Jeff Brown
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: