@@ -1635,34 +1635,43 @@ checkOrNeq _ (T_OrIf id lhs rhs) = sequence_ $ do
16351635checkOrNeq _ _ = return ()
16361636
16371637
1638- prop_checkAndEq1 = verify checkAndEq " if [[ $lol -eq cow && $lol -eq foo ]]; then echo foo; fi"
1639- prop_checkAndEq2 = verify checkAndEq " (( a==lol && a==foo ))"
1638+ prop_checkAndEq1 = verifyNot checkAndEq " cow=0; foo=0; if [[ $lol -eq cow && $lol -eq foo ]]; then echo foo; fi"
1639+ prop_checkAndEq2 = verifyNot checkAndEq " lol=0 foo=0; (( a==lol && a==foo ))"
16401640prop_checkAndEq3 = verify checkAndEq " [ \" $a\" = lol && \" $a\" = foo ]"
16411641prop_checkAndEq4 = verifyNot checkAndEq " [ a = $cow && b = $foo ]"
16421642prop_checkAndEq5 = verifyNot checkAndEq " [[ $a = /home && $a = */public_html/* ]]"
16431643prop_checkAndEq6 = verify checkAndEq " [ $a = a ] && [ $a = b ]"
16441644prop_checkAndEq7 = verify checkAndEq " [ $a = a ] && [ $a = b ] || true"
16451645prop_checkAndEq8 = verifyNot checkAndEq " [[ $a == x && $a == x ]]"
16461646prop_checkAndEq9 = verifyNot checkAndEq " [ 0 -eq $FOO ] && [ 0 -eq $BAR ]"
1647+ prop_checkAndEq10 = verify checkAndEq " (( a == 1 && a == 2 ))"
1648+ prop_checkAndEq11 = verify checkAndEq " [ $x -eq 1 ] && [ $x -eq 2 ]"
1649+ prop_checkAndEq12 = verify checkAndEq " [ 1 -eq $x ] && [ $x -eq 2 ]"
1650+ prop_checkAndEq13 = verifyNot checkAndEq " [ 1 -eq $x ] && [ $x -eq 1 ]"
1651+ prop_checkAndEq14 = verifyNot checkAndEq " [ $a = $b ] && [ $a = $c ]"
1652+
1653+ checkAndEqOperands " -eq" rhs1 rhs2 = isLiteralNumber rhs1 && isLiteralNumber rhs2
1654+ checkAndEqOperands op rhs1 rhs2 | op == " =" || op == " ==" = isLiteral rhs1 && isLiteral rhs2
1655+ checkAndEqOperands _ _ _ = False
16471656
16481657-- For test-level "and": [ x = y -a x = z ]
16491658checkAndEq _ (TC_And id typ op (TC_Binary _ _ op1 lhs1 rhs1 ) (TC_Binary _ _ op2 lhs2 rhs2))
1650- | ( op1 == op2 && (op1 == " -eq " || op1 == " = " || op1 == " == " )) && lhs1 == lhs2 && rhs1 /= rhs2 && not ( any isGlob [ rhs1, rhs2]) =
1651- warn id 2055 $ " You probably wanted " ++ (if typ == SingleBracket then " -o" else " ||" ) ++ " here, otherwise it's always false."
1659+ | op1 == op2 && lhs1 == lhs2 && rhs1 /= rhs2 && checkAndEqOperands op1 rhs1 rhs2 =
1660+ warn id 2333 $ " You probably wanted " ++ (if typ == SingleBracket then " -o" else " ||" ) ++ " here, otherwise it's always false."
16521661
16531662-- For arithmetic context "and"
1654- checkAndEq _ (TA_Binary id " &&" (TA_Binary _ " ==" word1 _ ) (TA_Binary _ " ==" word2 _ ))
1655- | word1 == word2 =
1656- warn id 2056 " You probably wanted || here, otherwise it's always false."
1663+ checkAndEq _ (TA_Binary id " &&" (TA_Binary _ " ==" lhs1 rhs1 ) (TA_Binary _ " ==" lhs2 rhs2 ))
1664+ | lhs1 == lhs2 && isLiteralNumber rhs1 && isLiteralNumber rhs2 =
1665+ warn id 2334 " You probably wanted || here, otherwise it's always false."
16571666
16581667-- For command level "and": [ x = y ] && [ x = z ]
16591668checkAndEq _ (T_AndIf id lhs rhs) = sequence_ $ do
16601669 (lhs1, op1, rhs1) <- getExpr lhs
16611670 (lhs2, op2, rhs2) <- getExpr rhs
1662- guard $ op1 == op2 && op1 `elem` [ " -eq " , " = " , " == " ]
1671+ guard $ op1 == op2
16631672 guard $ lhs1 == lhs2 && rhs1 /= rhs2
1664- guard . not $ any isGlob [ rhs1, rhs2]
1665- return $ warn id 2252 " You probably wanted || here, otherwise it's always false."
1673+ guard $ checkAndEqOperands op1 rhs1 rhs2
1674+ return $ warn id 2333 " You probably wanted || here, otherwise it's always false."
16661675 where
16671676 getExpr x =
16681677 case x of
0 commit comments