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

Memoization doesn't seem to work for trait methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.12
    • 4.0.0-alpha-3
    • ast builder
    • None

    Description

      I wanted to memorize a method in a trait, basically the following:

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

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

      Attachments

        Activity

          People

            emilles Eric Milles
            paplorinc LÅ‘rinc Pap
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 10m
                1h 10m