Added reason in messages about subshells
This commit is contained in:
parent
7e3a20c14a
commit
de31835676
|
@ -209,21 +209,21 @@ prop_subshellAssignmentCheck5 = verifyFull subshellAssignmentCheck "cat foo |
|
||||||
prop_subshellAssignmentCheck6 = verifyFull subshellAssignmentCheck "( export lol=$(ls); ); echo $lol;"
|
prop_subshellAssignmentCheck6 = verifyFull subshellAssignmentCheck "( export lol=$(ls); ); echo $lol;"
|
||||||
subshellAssignmentCheck t map =
|
subshellAssignmentCheck t map =
|
||||||
let flow = getVariableFlow t
|
let flow = getVariableFlow t
|
||||||
check = findSubshelled flow [[]] Map.empty
|
check = findSubshelled flow [("oops",[])] Map.empty
|
||||||
in snd $ runState check map
|
in snd $ runState check map
|
||||||
|
|
||||||
|
|
||||||
data Scope = SubshellScope | NoneScope deriving (Show, Eq)
|
data Scope = SubshellScope String | NoneScope deriving (Show, Eq)
|
||||||
data StackData = StackScope Scope | StackScopeEnd | Assignment (Id, String) | Reference (Id, String) deriving (Show, Eq)
|
data StackData = StackScope Scope | StackScopeEnd | Assignment (Id, String) | Reference (Id, String) deriving (Show, Eq)
|
||||||
data VariableState = Dead Id | Alive deriving (Show, Eq)
|
data VariableState = Dead Id String | Alive deriving (Show, Eq)
|
||||||
|
|
||||||
leadType t =
|
leadType t =
|
||||||
case t of
|
case t of
|
||||||
T_DollarExpansion _ _ -> SubshellScope
|
T_DollarExpansion _ _ -> SubshellScope "$(..)"
|
||||||
T_Backgrounded _ _ -> SubshellScope
|
T_Backgrounded _ _ -> SubshellScope "backgrounding &"
|
||||||
T_Subshell _ _ -> SubshellScope
|
T_Subshell _ _ -> SubshellScope "(..) group"
|
||||||
-- This considers the pipeline one subshell. Consider fixing.
|
-- This considers the pipeline one subshell. Consider fixing.
|
||||||
T_Pipeline _ (_:_:[]) -> SubshellScope
|
T_Pipeline _ (_:_:[]) -> SubshellScope "pipeline"
|
||||||
_ -> NoneScope
|
_ -> NoneScope
|
||||||
|
|
||||||
|
|
||||||
|
@ -285,21 +285,21 @@ getVariableFlow t =
|
||||||
let (_, stack) = runState (doStackAnalysis startScope endScope t) []
|
let (_, stack) = runState (doStackAnalysis startScope endScope t) []
|
||||||
in reverse stack
|
in reverse stack
|
||||||
|
|
||||||
findSubshelled :: [StackData] -> [[(Id,String)]] -> (Map.Map String VariableState) -> State (Map.Map Id Metadata) ()
|
findSubshelled :: [StackData] -> [(String, [(Id,String)])] -> (Map.Map String VariableState) -> State (Map.Map Id Metadata) ()
|
||||||
findSubshelled [] _ _ = return ()
|
findSubshelled [] _ _ = return ()
|
||||||
findSubshelled ((Assignment x@(id, str)):rest) (scope:lol) deadVars =
|
findSubshelled ((Assignment x@(id, str)):rest) ((reason,scope):lol) deadVars =
|
||||||
findSubshelled rest ((x:scope):lol) $ Map.insert str Alive deadVars
|
findSubshelled rest ((reason, x:scope):lol) $ Map.insert str Alive deadVars
|
||||||
findSubshelled ((Reference (readId, str)):rest) scopes deadVars = do
|
findSubshelled ((Reference (readId, str)):rest) scopes deadVars = do
|
||||||
case Map.findWithDefault Alive str deadVars of
|
case Map.findWithDefault Alive str deadVars of
|
||||||
Alive -> return ()
|
Alive -> return ()
|
||||||
Dead writeId -> do
|
Dead writeId reason -> do
|
||||||
addNoteFor writeId $ Note InfoC $ str ++ " is here modified inside a subshell, but is later used outside."
|
addNoteFor writeId $ Note InfoC $ "Modification of " ++ str ++ " is local (to subshell caused by "++ reason ++")."
|
||||||
addNoteFor readId $ Note InfoC $ str ++ " was last modified in a subshell, and that change might be lost."
|
addNoteFor readId $ Note InfoC $ str ++ " was modified in a subshell. That change might be lost."
|
||||||
findSubshelled rest scopes deadVars
|
findSubshelled rest scopes deadVars
|
||||||
|
|
||||||
findSubshelled ((StackScope SubshellScope):rest) scopes deadVars =
|
findSubshelled ((StackScope (SubshellScope reason)):rest) scopes deadVars =
|
||||||
findSubshelled rest ([]:scopes) deadVars
|
findSubshelled rest ((reason,[]):scopes) deadVars
|
||||||
|
|
||||||
findSubshelled ((StackScopeEnd):rest) (scope:oldScopes) deadVars =
|
findSubshelled ((StackScopeEnd):rest) ((reason, scope):oldScopes) deadVars =
|
||||||
findSubshelled rest oldScopes $ foldl (\m (id, var) -> Map.insert var (Dead id) m) deadVars scope
|
findSubshelled rest oldScopes $ foldl (\m (id, var) -> Map.insert var (Dead id reason) m) deadVars scope
|
||||||
------
|
------
|
||||||
|
|
Loading…
Reference in New Issue