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

Problem With Runtime Metaprogramming Over A Trait Method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 4.0.0-rc-2
    • None
    • None

    Description

      It looks like I cannot runtime metaprogram over a trait method.

      The attached metaprogramovertrait.zip file contains the following:

      src/main/groovy/demo/SomeClass.groovy
      package demo
      
      class SomeClass implements SomeTrait {}
      
      src/main/groovy/demo/SomeTrait.groovy
      package demo
      
      trait SomeTrait {
          void someMethod() {
          }
      }
      
      src/test/groovy/demo/SomeClassSpec.groovy
      package demo
      
      import spock.lang.Specification
      class SomeClassSpec extends Specification {
      
          void 'test something'() {
              given:
              SomeClass.metaClass.someMethod = { ->
                  throw new UnsupportedOperationException()
              }
      
              when:
              new SomeClass().someMethod()
      
              then:
              UnsupportedOperationException ex = thrown()
          }
      }
      

      If I remove the method from the trait, the test passes.

      Attachments

        1. metaprogramovertrait.zip
          51 kB
          Jeff Scott Brown

        Activity

          People

            emilles Eric Milles
            jeffscottbrown Jeff Scott Brown
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: