From df068bc8edb0234203a89bddbf5ac43e7edb878e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 5 Nov 2017 18:35:50 -0500 Subject: [PATCH] Fix isClosingFileOp (fixes issue #862) The isClosingFileOp function expected closing file ops to use T_IoFile, but they actually use T_IoDuplicate; so it effectively always returned False. --- ShellCheck/Analytics.hs | 1 + ShellCheck/AnalyzerLib.hs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f524a87..6bd4e93 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -1810,6 +1810,7 @@ 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}" prop_checkUnused36= verifyNotTree checkUnusedAssignments "if [[ -v foo ]]; then true; fi" +prop_checkUnused37= verifyNotTree checkUnusedAssignments "fd=2; exec {fd}>&-" checkUnusedAssignments params t = execWriter (mapM_ warnFor unused) where flow = variableFlow params diff --git a/ShellCheck/AnalyzerLib.hs b/ShellCheck/AnalyzerLib.hs index 04ac457..b2d4c93 100644 --- a/ShellCheck/AnalyzerLib.hs +++ b/ShellCheck/AnalyzerLib.hs @@ -487,8 +487,8 @@ getModifiedVariables t = isClosingFileOp op = case op of - T_IoFile _ (T_GREATAND _) (T_NormalWord _ [T_Literal _ "-"]) -> True - T_IoFile _ (T_LESSAND _) (T_NormalWord _ [T_Literal _ "-"]) -> True + T_IoDuplicate _ (T_GREATAND _) "-" -> True + T_IoDuplicate _ (T_LESSAND _) "-" -> True _ -> False