Skip to content

Commit 566b295

Browse files
committed
Record the command's id in CFSetExitCode for built-in handlers
handleCommand receives the whole T_SimpleCommand as `cmd`, and the ordinary path registers the exit code against it through `handleOthers (getId cmd) ...`. regularExpansionWithStatus, used by the built-in table, shadowed that name with the command's first word, so printf, unset, wait, mapfile, readarray, read and the four DEFINE_* commands recorded their exit code under the id of a T_NormalWord instead. Consumers that resolve the id through idMap then get a word where they expect a command. checkOverwrittenExitCode is one of them: getCommandBasename is Nothing for a T_NormalWord, so isPrinting never matched and SC2320 stayed silent for printf while firing for echo, which is not in the table and goes through handleOthers. Drop the shadowing pattern so cmd again refers to the command. Fixes #3490
1 parent 9af7ee2 commit 566b295

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

src/ShellCheck/Analytics.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5097,6 +5097,8 @@ prop_checkOverwrittenExitCode5 = verify checkOverwrittenExitCode "x; if [ $? -eq
50975097
prop_checkOverwrittenExitCode6 = verify checkOverwrittenExitCode "x; [ $? -gt 0 ] && fail=$?"
50985098
prop_checkOverwrittenExitCode7 = verifyNot checkOverwrittenExitCode "[ 1 -eq 2 ]; status=$?"
50995099
prop_checkOverwrittenExitCode8 = verifyNot checkOverwrittenExitCode "[ 1 -eq 2 ]; exit $?"
5100+
prop_checkOverwrittenExitCode9 = verify checkOverwrittenExitCode "x; printf '%d' $?; [ $? -eq 0 ]"
5101+
prop_checkOverwrittenExitCode10 = verifyNot checkOverwrittenExitCode "read -r x; [ $? -eq 0 ]"
51005102
checkOverwrittenExitCode params t =
51015103
case t of
51025104
T_DollarBraced id _ val | getLiteralString val == Just "?" -> check id

src/ShellCheck/CFG.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ handleCommand cmd vars args literalCmd = do
11961196

11971197
linkRanges $ [args] ++ assignments ++ [exe] ++ dropAssignments
11981198

1199-
regularExpansionWithStatus vars args@(cmd NE.:| _) p = do
1199+
regularExpansionWithStatus vars args p = do
12001200
initial <- regularExpansion vars (NE.toList args) p
12011201
status <- newNodeRange $ CFSetExitCode (getId cmd)
12021202
linkRange initial status

0 commit comments

Comments
 (0)