Refine #2544 to not warn when $? postdominates [ ] (fixes #2544)

This commit is contained in:
Vidar Holen 2022-07-25 11:57:04 -07:00
parent f1148b8b41
commit e9784fa9a7
2 changed files with 21 additions and 2 deletions

View file

@ -56,6 +56,7 @@ module ShellCheck.CFGAnalysis (
,SpaceStatus (..)
,getIncomingState
,getOutgoingState
,doesPostDominate
,ShellCheck.CFGAnalysis.runTests -- STRIP
) where
@ -140,6 +141,15 @@ getOutgoingState analysis id = do
(start,end) <- M.lookup id $ tokenToRange analysis
snd <$> M.lookup end (nodeToData analysis)
-- Conveniently determine whether one node postdominates another,
-- i.e. whether 'target' always unconditionally runs after 'base'.
doesPostDominate :: CFGAnalysis -> Id -> Id -> Bool
doesPostDominate analysis target base = fromMaybe False $ do
(_, baseEnd) <- M.lookup base $ tokenToRange analysis
(targetStart, _) <- M.lookup target $ tokenToRange analysis
postDoms <- M.lookup baseEnd $ postDominators analysis
return $ S.member targetStart postDoms
getDataForNode analysis node = M.lookup node $ nodeToData analysis
-- The current state of data flow at a point in the program, potentially as a diff