Merge pull request #1298 from ngzhian/1268

Fix false positive when indexing into array in cond
This commit is contained in:
Vidar Holen 2018-07-21 13:43:45 -07:00 committed by GitHub
commit c3ac4c3d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -520,7 +520,7 @@ readConditionContents single =
notFollowedBy2 (try (spacing >> string "]")) notFollowedBy2 (try (spacing >> string "]"))
x <- readNormalWord x <- readNormalWord
pos <- getPosition pos <- getPosition
when (endedWith "]" x) $ do when (endedWith "]" x && notArrayIndex x) $ do
parseProblemAt pos ErrorC 1020 $ parseProblemAt pos ErrorC 1020 $
"You need a space before the " ++ (if single then "]" else "]]") ++ "." "You need a space before the " ++ (if single then "]" else "]]") ++ "."
fail "Missing space before ]" fail "Missing space before ]"
@ -534,6 +534,8 @@ readConditionContents single =
case last s of T_Literal id s -> str `isSuffixOf` s case last s of T_Literal id s -> str `isSuffixOf` s
_ -> False _ -> False
endedWith _ _ = False endedWith _ _ = False
notArrayIndex (T_NormalWord id s@(_:T_Literal _ t:_)) = t /= "["
notArrayIndex _ = True
readCondAndOp = readAndOrOp TC_And "&&" False <|> readAndOrOp TC_And "-a" True readCondAndOp = readAndOrOp TC_And "&&" False <|> readAndOrOp TC_And "-a" True