Fixed bug where (($b)) counted as a positional reference

This commit is contained in:
Vidar Holen 2014-10-18 19:51:13 -07:00
parent 39b88bbaac
commit 90bafb9aba
1 changed files with 8 additions and 4 deletions

View File

@ -2068,12 +2068,12 @@ getReferencedVariables t =
(t, t, getBracedReference str) : (t, t, getBracedReference str) :
map (\x -> (l, l, x)) (getIndexReferences str) map (\x -> (l, l, x)) (getIndexReferences str)
TA_Expansion id _ -> maybeToList $ do TA_Expansion id _ -> maybeToList $ do
str <- getLiteralStringExt (const $ return "#") t str <- getLiteralStringExt literalizer t
firstChar <- if null str then fail "" else return $ head str guard . not $ null str
when (isDigit firstChar) $ fail "is a number" when (isDigit $ head str) $ fail "is a number"
return (t, t, getBracedReference str) return (t, t, getBracedReference str)
T_Assignment id mode str _ word -> T_Assignment id mode str _ word ->
(if mode == Append then [(t, t, str)] else []) ++ (specialReferences str t word) [(t, t, str) | mode == Append] ++ specialReferences str t word
x -> getReferencedVariableCommand x x -> getReferencedVariableCommand x
where where
-- Try to reduce false positives for unused vars only referenced from evaluated vars -- Try to reduce false positives for unused vars only referenced from evaluated vars
@ -2087,6 +2087,9 @@ getReferencedVariables t =
getVariablesFromLiteralToken word getVariablesFromLiteralToken word
else [] else []
literalizer (TA_Index {}) = return "" -- x[0] becomes a reference of x
literalizer _ = Nothing
-- Try to get referenced variables from a literal string like "$foo" -- Try to get referenced variables from a literal string like "$foo"
-- Ignores tons of cases like arithmetic evaluation and array indices. -- Ignores tons of cases like arithmetic evaluation and array indices.
prop_getVariablesFromLiteral1 = prop_getVariablesFromLiteral1 =
@ -2715,6 +2718,7 @@ prop_checkUnpassedInFunctions5 = verifyNotTree checkUnpassedInFunctions "foo() {
prop_checkUnpassedInFunctions6 = verifyNotTree checkUnpassedInFunctions "foo() { set -- *; echo $1; }; foo" prop_checkUnpassedInFunctions6 = verifyNotTree checkUnpassedInFunctions "foo() { set -- *; echo $1; }; foo"
prop_checkUnpassedInFunctions7 = verifyTree checkUnpassedInFunctions "foo() { echo $1; }; foo; foo;" prop_checkUnpassedInFunctions7 = verifyTree checkUnpassedInFunctions "foo() { echo $1; }; foo; foo;"
prop_checkUnpassedInFunctions8 = verifyNotTree checkUnpassedInFunctions "foo() { echo $((1)); }; foo;" prop_checkUnpassedInFunctions8 = verifyNotTree checkUnpassedInFunctions "foo() { echo $((1)); }; foo;"
prop_checkUnpassedInFunctions9 = verifyNotTree checkUnpassedInFunctions "foo() { echo $(($b)); }; foo;"
checkUnpassedInFunctions params root = checkUnpassedInFunctions params root =
execWriter $ mapM_ warnForGroup referenceGroups execWriter $ mapM_ warnForGroup referenceGroups
where where