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

Trait static methods are not resolved when called from closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.8
    • 4.0.18
    • None

    Description

      In trait when calling a method from closure. MissingMethodException thrown inside that method when calling any other trait static method. (This is not the case when class is used instead of trait)

      When in "ugly" case, this context is switched to TestTrait$Trait$Helper from TestClass.

      Test code
      TestClass.getLevel1() // run test
      
      class TestClass implements TestTrait{}
      
      trait TestTrait{
          static getLevel1(){  println(['getLevel1':this])
              getLevel2('good') // runs
              def me = this
              'bad'.with{me.getLevel2(it)} // runs
              'ugly'.with{getLevel2(it)} // throws getLevel3 not found
          }
          static getLevel2(String s){  println(['getLevel2':this])
              getLevel3(s) // throws MissingMethodException for ugly
          }
          static getLevel3(String s){  println(['getLevel3':this])
              s
          }
      }
      
      Output
      No signature of method: static TestTrait.getLevel3() is applicable for argument types: (String) values: [ugly]

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: