Don't warn about unused vars with readonly -f

This commit is contained in:
Vidar Holen 2016-09-24 13:42:20 -07:00
parent 1c0ec9c6f6
commit 3a7dc86de1
2 changed files with 9 additions and 2 deletions

View File

@ -2136,6 +2136,7 @@ prop_checkUnassignedReferences22= verifyNotTree checkUnassignedReferences "echo
prop_checkUnassignedReferences23= verifyTree checkUnassignedReferences "declare -a foo; foo[bar]=42;" prop_checkUnassignedReferences23= verifyTree checkUnassignedReferences "declare -a foo; foo[bar]=42;"
prop_checkUnassignedReferences24= verifyNotTree checkUnassignedReferences "declare -A foo; foo[bar]=42;" prop_checkUnassignedReferences24= verifyNotTree checkUnassignedReferences "declare -A foo; foo[bar]=42;"
prop_checkUnassignedReferences25= verifyNotTree checkUnassignedReferences "declare -A foo=(); foo[bar]=42;" prop_checkUnassignedReferences25= verifyNotTree checkUnassignedReferences "declare -A foo=(); foo[bar]=42;"
prop_checkUnassignedReferences26= verifyNotTree checkUnassignedReferences "a::b() { foo; }; readonly -f a::b"
checkUnassignedReferences params t = warnings checkUnassignedReferences params t = warnings
where where
(readMap, writeMap) = execState (mapM tally $ variableFlow params) (Map.empty, Map.empty) (readMap, writeMap) = execState (mapM tally $ variableFlow params) (Map.empty, Map.empty)

View File

@ -361,7 +361,10 @@ getReferencedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Litera
"declare" -> if any (`elem` flags) ["x", "p"] "declare" -> if any (`elem` flags) ["x", "p"]
then concatMap getReference rest then concatMap getReference rest
else [] else []
"readonly" -> concatMap getReference rest "readonly" ->
if any (`elem` flags) ["f", "p"]
then []
else concatMap getReference rest
"trap" -> "trap" ->
case rest of case rest of
head:_ -> map (\x -> (head, head, x)) $ getVariablesFromLiteralToken head head:_ -> map (\x -> (head, head, x)) $ getVariablesFromLiteralToken head
@ -395,7 +398,10 @@ getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal
"typeset" -> declaredVars "typeset" -> declaredVars
"local" -> concatMap getModifierParamString rest "local" -> concatMap getModifierParamString rest
"readonly" -> concatMap getModifierParamString rest "readonly" ->
if any (`elem` flags) ["f", "p"]
then []
else concatMap getModifierParamString rest
"set" -> maybeToList $ do "set" -> maybeToList $ do
params <- getSetParams rest params <- getSetParams rest
return (base, base, "@", DataString $ SourceFrom params) return (base, base, "@", DataString $ SourceFrom params)