seanjensengrey / kiama

Automatically exported from code.google.com/p/kiama
GNU Lesser General Public License v3.0
0 stars 0 forks source link

hasBeenComputedAt should be reset when resetMemo has been called #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Test case:

     object o extends Attribution {
       val a: CachedAttribute[String, String] = attr(identity _)
     }
     o.a("1") === "1"
     o.a.hasBeenComputedAt("1") === true
     o.resetMemo()

     // this doesn't pass at the moment
     o.a.hasBeenComputedAt("1") === false

Original issue reported on code.google.com by etorrebo...@gmail.com on 5 Mar 2013 at 2:23

GoogleCodeExporter commented 9 years ago
I suppose that fix is merely:

  private def resetIfMemoVersionHasIncremented = 
     if (memoVersion != MemoState.MEMO_VERSION) {
       memoVersion = MemoState.MEMO_VERSION
       memo.clear
     }

  def hasBeenComputedAt (t : T) : Boolean = {
     resetIfMemoVersionHasIncremented
     // this is simpler btw :-)
     memo.get (t).isDefined
  }

Original comment by etorrebo...@gmail.com on 5 Mar 2013 at 2:27

GoogleCodeExporter commented 9 years ago
Thanks for the report. Fixed in r22fa69649631.

BTW, the isDefined trick doesn't work here because it's a Java IdentityHashMap, 
not a Scala one. I have simplified the check to != null, though...

Original comment by inkytonik on 5 Mar 2013 at 4:44

GoogleCodeExporter commented 9 years ago
I confirm that everything works fine. Thanks Tony.

Original comment by etorrebo...@gmail.com on 7 Mar 2013 at 3:54

GoogleCodeExporter commented 9 years ago
Thanks for the ack Eric.

Original comment by inkytonik on 7 Mar 2013 at 8:36