From a30ac402eb39d3e60cd3a64abd48d00c85d49bab Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 27 Jul 2022 11:29:55 -0700 Subject: [PATCH] Don't use & for updates as result is unspecified This fixes `Prelude.foldl1: empty list []` when script has `( exit )` --- src/ShellCheck/CFG.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/CFG.hs b/src/ShellCheck/CFG.hs index ad05e93..39747cf 100644 --- a/src/ShellCheck/CFG.hs +++ b/src/ShellCheck/CFG.hs @@ -1203,6 +1203,9 @@ tokenToParts t = _ -> [maybe CFStringUnknown CFStringLiteral $ getLiteralString t] +-- Like & but well defined when the node already exists +safeUpdate ctx@(_,node,_,_) graph = ctx & (delNode node graph) + -- Change all subshell invocations to instead link directly to their contents. -- This is used for producing dominator trees. inlineSubshells :: CFGraph -> CFGraph @@ -1223,7 +1226,7 @@ inlineSubshells graph = relinkedGraph endToNexts = (endIncoming, endNode, endLabel, outgoing) (endIncoming, endNode, endLabel, _) = context graph end in - subshellToStart & (endToNexts & graph) + subshellToStart `safeUpdate` (endToNexts `safeUpdate` graph) findEntryNodes :: CFGraph -> [Node] findEntryNodes graph = ufold find [] graph @@ -1259,7 +1262,7 @@ findPostDominators mainexit graph = asSetMap inlined = inlineSubshells graph terminals = findTerminalNodes inlined (incoming, _, label, outgoing) = context graph mainexit - withExitEdges = (incoming ++ map (\c -> (CFEFlow, c)) terminals, mainexit, label, outgoing) & inlined + withExitEdges = (incoming ++ map (\c -> (CFEFlow, c)) terminals, mainexit, label, outgoing) `safeUpdate` inlined reversed = grev withExitEdges postDoms = dom reversed mainexit asSetMap = M.fromList $ map (\(node, list) -> (node, S.fromList list)) postDoms