fix an occasional stack overflow error due to infinite recursion in Posting/Transaction equality tests

This was happening with balance command on certain timelog entries, since 0.8.
Now, when testing two postings for equality, their parent transaction's identity is ignored.
This commit is contained in:
Simon Michael 2010-05-22 00:45:35 +00:00
parent 30788ee7fd
commit be30aac3f5
2 changed files with 20 additions and 2 deletions

View File

@ -81,7 +81,12 @@ data Posting = Posting {
ptype :: PostingType,
ptransaction :: Maybe Transaction -- ^ this posting's parent transaction (co-recursive types).
-- Tying this knot gets tedious, Maybe makes it easier/optional.
} deriving (Eq)
}
-- The equality test for postings ignores the parent transaction's
-- identity, to avoid infinite loops.
instance Eq Posting where
(==) (Posting a1 b1 c1 d1 e1 _) (Posting a2 b2 c2 d2 e2 _) = a1==a2 && b1==b2 && c1==c2 && d1==d2 && e1==e2
data Transaction = Transaction {
tdate :: Day,
@ -90,7 +95,7 @@ data Transaction = Transaction {
tcode :: String,
tdescription :: String,
tcomment :: String,
tpostings :: [Posting],
tpostings :: [Posting], -- ^ this transaction's postings (co-recursive types).
tpreceding_comment_lines :: String
} deriving (Eq)

View File

@ -0,0 +1,13 @@
# this gave a stack space overflow error with 0.8-0.9 due to infinite
# recursion in Posting and Transaction's equality tests:
bin/hledger -f - balance
<<<
i 2010/1/1 09:00:00 a:b
o 2010/1/1 09:03:00
>>>=0
# incidentally this didn't trigger it.. go figure
bin/hledger -f - balance
<<<
i 2010/1/1 09:00:00 a:b
o 2010/1/1 09:02:00
>>>=0