[ 
https://issues.apache.org/jira/browse/GROOVY-7500?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles resolved GROOVY-7500.
---------------------------------
    Fix Version/s: 4.0.0-rc-2
       Resolution: Fixed

https://github.com/apache/groovy/commit/55fb428c4f6dfad37be5f752282a97089cb1b5ad

> Problem With Runtime Metaprogramming Over A Trait Method
> --------------------------------------------------------
>
>                 Key: GROOVY-7500
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7500
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.3
>            Reporter: Jeff Scott Brown
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-rc-2
>
>         Attachments: metaprogramovertrait.zip
>
>
> It looks like I cannot runtime metaprogram over a trait method.  
> The attached metaprogramovertrait.zip file contains the following:
> {code:title=src/main/groovy/demo/SomeClass.groovy}
> package demo
> class SomeClass implements SomeTrait {}
> {code}
> {code:title=src/main/groovy/demo/SomeTrait.groovy}
> package demo
> trait SomeTrait {
>     void someMethod() {
>     }
> }
> {code}
> {code:title=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()
>     }
> }
> {code}
> If I remove the method from the trait, the test passes.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to