You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/12/19 19:07:00 UTC

[jira] [Assigned] (GROOVY-7500) Problem With Runtime Metaprogramming Over A Trait Method

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

Eric Milles reassigned GROOVY-7500:
-----------------------------------

    Assignee: Eric Milles

> 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
>         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)