From a9e7bf1950ed50bdfbc818710085c6414f8bf20e Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 10 Dec 2023 19:13:34 -0800 Subject: [PATCH] Reparse indices after attaching here docs (fixes #2846) --- src/ShellCheck/Checker.hs | 3 +++ src/ShellCheck/Parser.hs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Checker.hs b/src/ShellCheck/Checker.hs index c79f90fbb..6c9166fc5 100644 --- a/src/ShellCheck/Checker.hs +++ b/src/ShellCheck/Checker.hs @@ -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 <> ./test\n $(( 1 + my_array[1] ))\nEOF" return [] runTests = $quickCheckAll diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index abd4d9404..701010fd2 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -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 @@ -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