Don't trigger constant checks for -ot/-ef/-nt

This commit is contained in:
Vidar Holen 2015-10-17 09:28:29 -07:00
parent a4b4954a23
commit 8d9d4533c3
1 changed files with 7 additions and 4 deletions

View File

@ -1293,15 +1293,18 @@ prop_checkConstantIfs2b= verifyNot checkConstantIfs "[[ n -le 4 ]]"
prop_checkConstantIfs3 = verify checkConstantIfs "[[ $n -le 4 && n != 2 ]]"
prop_checkConstantIfs4 = verifyNot checkConstantIfs "[[ $n -le 3 ]]"
prop_checkConstantIfs5 = verifyNot checkConstantIfs "[[ $n -le $n ]]"
checkConstantIfs _ (TC_Binary id typ op lhs rhs) | isStatic =
prop_checkConstantIfs6 = verifyNot checkConstantIfs "[[ a -ot b ]]"
prop_checkConstantIfs7 = verifyNot checkConstantIfs "[ a -nt b ]"
checkConstantIfs _ (TC_Binary id typ op lhs rhs) | not isDynamic =
when (isJust lLit && isJust rLit) $
warn id 2050 "This expression is constant. Did you forget the $ on a variable?"
where
lLit = getLiteralString lhs
rLit = getLiteralString rhs
isStatic =
typ == SingleBracket ||
op `elem` [ "=", "==", "!=", "<=", ">=", "=~", ">", "<" ]
isDynamic =
op `elem` [ "-lt", "-gt", "-le", "-ge", "-eq", "-ne" ]
&& typ == DoubleBracket
|| op `elem` [ "-nt", "-ot", "-ef"]
checkConstantIfs _ _ = return ()
prop_checkLiteralBreakingTest = verify checkLiteralBreakingTest "[[ a==$foo ]]"