From b46aa1330ff5bc7e3e53c07400da76e52e53591c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 5 Aug 2022 13:44:56 +0100 Subject: [PATCH] fix: don't reverse account display order with include files (#1909) --- hledger-lib/Hledger/Read/JournalReader.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index d28d4db6a..2d588fc4c 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -307,7 +307,11 @@ includedirectivep = do let r = fromMaybe reader $ findReader Nothing (Just prefixedpath) parser = rParser r dbg6IO "trying reader" (rFormat r) - updatedChildj <- journalAddFile (filepath, childInput) <$> + -- Included files's lists are still reversed, because not yet journalFinalise'd, + -- which confuses the calculation of account declaration order across multiple files (#1909). + -- Unreverse just the acct declarations to fix that without disturbing anything else. + let reversedecls j = j{jdeclaredaccounts = reverse $ jdeclaredaccounts j} + updatedChildj <- (journalAddFile (filepath, childInput) . reversedecls) <$> parseIncludeFile parser initChildj filepath childInput -- discard child's parse info, combine other fields