Merge pull request #4003 from ethereum/bool_vars_comparison

BREAKING: Bool variables should not allow arithmetic comparison
This commit is contained in:
chriseth
2018-05-02 15:56:06 +02:00
committed by GitHub
5 changed files with 60 additions and 35 deletions
+1 -1
View File
@@ -1359,7 +1359,7 @@ TypePointer BoolType::binaryOperatorResult(Token::Value _operator, TypePointer c
{
if (category() != _other->category())
return TypePointer();
if (Token::isCompareOp(_operator) || _operator == Token::And || _operator == Token::Or)
if (_operator == Token::Equal || _operator == Token::NotEqual || _operator == Token::And || _operator == Token::Or)
return _other;
else
return TypePointer();
+1 -5
View File
@@ -472,11 +472,7 @@ void SMTChecker::compareOperation(BinaryOperation const& _op)
solUnimplementedAssert(SSAVariable::isBool(_op.annotation().commonType->category()), "Operation not yet supported");
value = make_shared<smt::Expression>(
op == Token::Equal ? (left == right) :
op == Token::NotEqual ? (left != right) :
op == Token::LessThan ? (!left && right) :
op == Token::LessThanOrEqual ? (!left || right) :
op == Token::GreaterThan ? (left && !right) :
/*op == Token::GreaterThanOrEqual*/ (left || !right)
/*op == Token::NotEqual*/ (left != right)
);
}
// TODO: check that other values for op are not possible.