[ 
https://issues.apache.org/jira/browse/GROOVY-9901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17268711#comment-17268711
 ] 

Eric Milles commented on GROOVY-9901:
-------------------------------------

Traits are applied in the semantic analysis phase, which is the same phase for 
{{groovy.transform.Memoized}}.  When the helper class is created, it needs an 
extra phase operation registered to get semantic analysis transforms processed.

> Memoization doesn't seem to work for trait methods
> --------------------------------------------------
>
>                 Key: GROOVY-9901
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9901
>             Project: Groovy
>          Issue Type: Bug
>          Components: ast builder
>    Affects Versions: 2.5.12
>            Reporter: Lőrinc Pap
>            Priority: Major
>
> I wanted to memorize a method in a trait, basically the following:
> {code:java}
> import groovy.transform.Memoized
> trait T {
>     @Memoized
>     double method() {
>         Math.random()
>     }
> }
> class A implements T {}
> class B implements T {}
> def a = new A()
> println a.method()
> println a.method()
> println new A().method()
> println new B().method(){code}
> And was surprised to see that they all returned different results.
> If this isn't supported, could we at least warn in case of AST 
> transformations being applied to traits (i.e. 
> [http://docs.groovy-lang.org/next/html/documentation/core-traits.html#_compatibility_with_ast_transformations)]?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to