mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
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:
parent
30788ee7fd
commit
be30aac3f5
@ -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)
|
||||
|
||||
|
13
tests/timelog-stack-overflow.test
Normal file
13
tests/timelog-stack-overflow.test
Normal 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
|
Loading…
Reference in New Issue
Block a user