Skip to content

Commit

Permalink
Reparse indices after attaching here docs (fixes #2846)
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Dec 11, 2023
1 parent f2729f7 commit a9e7bf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/ShellCheck/Checker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ prop_hereDocsAreParsedWithoutTrailingLinefeed = 1044 `elem` result
where
result = check "cat << eof"

prop_hereDocsWillHaveParsedIndices = null result
where
result = check "#!/bin/bash\nmy_array=(a b)\ncat <<EOF >> ./test\n $(( 1 + my_array[1] ))\nEOF"

return []
runTests = $quickCheckAll
6 changes: 3 additions & 3 deletions src/ShellCheck/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,8 @@ readScriptFile sourced = do
verifyEof
let script = T_Annotation annotationId annotations $
T_Script id shebang commands
reparseIndices script
userstate <- getState
reparseIndices $ reattachHereDocs script (hereDocMap userstate)
else do
many anyChar
id <- endSpan start
Expand Down Expand Up @@ -3487,8 +3488,7 @@ parseShell env name contents = do
return newParseResult {
prComments = map toPositionedComment $ nub $ parseNotes userstate ++ parseProblems state,
prTokenPositions = Map.map startEndPosToPos (positionMap userstate),
prRoot = Just $
reattachHereDocs script (hereDocMap userstate)
prRoot = Just script
}
Left err -> do
let context = contextStack state
Expand Down

0 comments on commit a9e7bf1

Please sign in to comment.