You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Lőrinc Pap (Jira)" <ji...@apache.org> on 2021/01/19 11:03:00 UTC

[jira] [Created] (GROOVY-9901) Memoization doesn't seem to work for trait methods

Lőrinc Pap created GROOVY-9901:
----------------------------------

             Summary: 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


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)