From a90b6d14b3de0f21db462afbc925444687feb2ca Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 5 Sep 2016 14:01:53 -0700 Subject: [PATCH] Count b as a reference in ${a:b} --- ShellCheck/Analytics.hs | 1 + ShellCheck/AnalyzerLib.hs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index af1a935..8658ab3 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -2088,6 +2088,7 @@ prop_checkUnused31= verifyTree checkUnusedAssignments "let 'a=1'" prop_checkUnused32= verifyTree checkUnusedAssignments "let a=b=c; echo $a" prop_checkUnused33= verifyNotTree checkUnusedAssignments "a=foo; [[ foo =~ ^{$a}$ ]]" prop_checkUnused34= verifyNotTree checkUnusedAssignments "foo=1; (( t = foo )); echo $t" +prop_checkUnused35= verifyNotTree checkUnusedAssignments "a=foo; b=2; echo ${a:b}" checkUnusedAssignments params t = execWriter (mapM_ warnFor unused) where flow = variableFlow params diff --git a/ShellCheck/AnalyzerLib.hs b/ShellCheck/AnalyzerLib.hs index 6f44f3f..e9c0a1e 100644 --- a/ShellCheck/AnalyzerLib.hs +++ b/ShellCheck/AnalyzerLib.hs @@ -474,11 +474,20 @@ getIndexReferences s = fromMaybe [] $ do where re = mkRegex "(\\[.*\\])" +getOffsetReferences mods = fromMaybe [] $ do + match <- matchRegex re mods + offsets <- match !!! 0 + return $ matchAllStrings variableNameRegex offsets + where + re = mkRegex "^ *:(.*)" + getReferencedVariables parents t = case t of T_DollarBraced id l -> let str = bracedString t in (t, t, getBracedReference str) : - map (\x -> (l, l, x)) (getIndexReferences str) + map (\x -> (l, l, x)) ( + getIndexReferences str + ++ getOffsetReferences (getBracedModifier str)) TA_Expansion id _ -> if isArithmeticAssignment t then []