Skip to content

Commit

Permalink
Revert "BREAKING: Bool variables should not allow arithmetic comparison"
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth authored May 2, 2018
1 parent 42289b6 commit 8debded
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 60 deletions.
5 changes: 0 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
### 0.5.0 (unreleased)
Features:
* Type Checker: Disallow arithmetic operations for Boolean variables.


### 0.4.24 (unreleased)

Features:
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ TypePointer BoolType::binaryOperatorResult(Token::Value _operator, TypePointer c
{
if (category() != _other->category())
return TypePointer();
if (_operator == Token::Equal || _operator == Token::NotEqual || _operator == Token::And || _operator == Token::Or)
if (Token::isCompareOp(_operator) || _operator == Token::And || _operator == Token::Or)
return _other;
else
return TypePointer();
Expand Down
6 changes: 5 additions & 1 deletion libsolidity/formal/SMTChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ 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::NotEqual ? (left != right) :
op == Token::LessThan ? (!left && right) :
op == Token::LessThanOrEqual ? (!left || right) :
op == Token::GreaterThan ? (left && !right) :
/*op == Token::GreaterThanOrEqual*/ (left || !right)
);
}
// TODO: check that other values for op are not possible.
Expand Down
29 changes: 29 additions & 0 deletions test/libsolidity/SMTChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,35 @@ BOOST_AUTO_TEST_CASE(bool_simple)
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function f(bool x) public pure {
bool y;
assert(x <= y);
}
}
)";
CHECK_WARNING(text, "Assertion violation happens here");
text = R"(
contract C {
function f(bool x) public pure {
bool y;
assert(x >= y);
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function f(bool x) public pure {
require(x);
bool y;
assert(x > y);
assert(y < x);
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}

BOOST_AUTO_TEST_CASE(bool_int_mixed)
Expand Down
53 changes: 0 additions & 53 deletions test/libsolidity/syntaxTests/types/bool_ops.sol

This file was deleted.

0 comments on commit 8debded

Please sign in to comment.