Recognize `read -ra foo` as arrays (fixes #1636)
This commit is contained in:
parent
ba2c20a08a
commit
380221a02c
|
@ -840,6 +840,7 @@ prop_checkArrayWithoutIndex6 = verifyTree checkArrayWithoutIndex "echo $PIPESTAT
|
|||
prop_checkArrayWithoutIndex7 = verifyTree checkArrayWithoutIndex "a=(a b); a+=c"
|
||||
prop_checkArrayWithoutIndex8 = verifyTree checkArrayWithoutIndex "declare -a foo; foo=bar;"
|
||||
prop_checkArrayWithoutIndex9 = verifyTree checkArrayWithoutIndex "read -r -a arr <<< 'foo bar'; echo \"$arr\""
|
||||
prop_checkArrayWithoutIndex10= verifyTree checkArrayWithoutIndex "read -ra arr <<< 'foo bar'; echo \"$arr\""
|
||||
checkArrayWithoutIndex params _ =
|
||||
doVariableFlowAnalysis readF writeF defaultMap (variableFlow params)
|
||||
where
|
||||
|
|
|
@ -676,9 +676,16 @@ getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal
|
|||
return (base, lastArg, name, DataArray SourceExternal)
|
||||
|
||||
-- get all the array variables used in read, e.g. read -a arr
|
||||
getReadArrayVariables args = do
|
||||
getReadArrayVariables args =
|
||||
map (getLiteralArray . snd)
|
||||
(filter (\(x,_) -> getLiteralString x == Just "-a") (zip (args) (tail args)))
|
||||
(filter (isArrayFlag . fst) (zip args (tail args)))
|
||||
|
||||
isArrayFlag x = fromMaybe False $ do
|
||||
str <- getLiteralString x
|
||||
return $ case str of
|
||||
'-':'-':_ -> False
|
||||
'-':str -> 'a' `elem` str
|
||||
_ -> False
|
||||
|
||||
-- get the FLAGS_ variable created by a shflags DEFINE_ call
|
||||
getFlagVariable (n:v:_) = do
|
||||
|
|
Loading…
Reference in New Issue