Add control flow tests for "and" and "or" operators

This commit is contained in:
wechman 2022-07-14 09:41:51 +02:00
parent 43a612e420
commit 1084a34f28
8 changed files with 90 additions and 65 deletions

View File

@ -57,6 +57,7 @@ unique_ptr<FunctionFlow> ControlFlowBuilder::createFunctionFlow(
bool ControlFlowBuilder::visit(BinaryOperation const& _operation) bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
{ {
solAssert(!!m_currentNode, ""); solAssert(!!m_currentNode, "");
visitNode(_operation);
switch (_operation.getOperator()) switch (_operation.getOperator())
{ {
@ -65,7 +66,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
{ {
visitNode(_operation); visitNode(_operation);
solAssert(!_operation.annotation().userDefinedFunction); solAssert(!_operation.annotation().userDefinedFunction);
visitNode(_operation);
appendControlFlow(_operation.leftExpression()); appendControlFlow(_operation.leftExpression());
auto nodes = splitFlow<2>(); auto nodes = splitFlow<2>();
@ -76,7 +76,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
} }
default: default:
{ {
visitNode(_operation);
if (_operation.annotation().userDefinedFunction) if (_operation.annotation().userDefinedFunction)
{ {
visitNode(_operation); visitNode(_operation);

View File

@ -0,0 +1,11 @@
struct S { bool f; }
contract C {
function f() public view {
S storage s;
s.f && true;
}
}
// ----
// TypeError 3464: (95-96): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.

View File

@ -0,0 +1,11 @@
struct S { bool f; }
contract C {
function f() public view {
S storage s;
s.f || true;
}
}
// ----
// TypeError 3464: (95-96): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.

View File

@ -2,16 +2,25 @@ struct S { bool f; }
using {add as +} for S; using {add as +} for S;
function add(S storage x, S storage) pure returns (S storage) { return x; } function add(S storage _s, S storage) pure returns (S storage) {
return _s;
_s.f = true;
}
contract C { contract C {
S s; function get() private returns (S storage) {
function f() public { S storage s;
S storage x = s; return s;
S storage y;
x + y;
} }
function f() public {
S storage s;
get() + s;
}
} }
// ---- // ----
// TypeError 3464: (230-231): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour. // Warning 5740: (131-142): Unreachable code.
// TypeError 3464: (238-239): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
// TypeError 3464: (311-312): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.

View File

@ -1,26 +0,0 @@
type Int is uint8;
using {
add as +,
sub as -,
mul as *
} for Int;
function f_view() view {}
function add(Int, Int) pure returns (Int) {
return Int.wrap(0);
}
function sub(Int, Int) returns (Int) {
return Int.wrap(0);
}
function mul(Int, Int) pure returns (Int) {
f_view();
return Int.wrap(0);
}
// ----
// Warning 2018: (179-243): Function state mutability can be restricted to pure
// TypeError 2527: (293-301): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".

View File

@ -1,30 +0,0 @@
type Int is uint8;
using {
add as +,
sub as -,
mul as *
} for Int;
function f_view() view {}
function f() {}
function add(Int, Int) view returns (Int) {
f_view();
return Int.wrap(0);
}
function sub(Int, Int) returns (Int) {
f_view();
return Int.wrap(0);
}
function mul(Int, Int) view returns (Int) {
f();
return Int.wrap(0);
}
// ----
// Warning 2018: (210-288): Function state mutability can be restricted to view
// TypeError 8961: (338-341): Function cannot be declared as view because this expression (potentially) modifies the state.

View File

@ -0,0 +1,21 @@
type Int is uint8;
using {
add as +
} for Int;
function add(Int, Int) pure returns (Int) {
return Int.wrap(0);
}
function f() pure {
Int.wrap(0) + Int.wrap(1);
}
function g() {
Int.wrap(0) + Int.wrap(1);
}
// ----
// Warning 2018: (178-225): Function state mutability can be restricted to pure

View File

@ -0,0 +1,30 @@
type Int is uint8;
using {
add as +
} for Int;
function f_view() view {}
function add(Int, Int) view returns (Int) {
f_view();
return Int.wrap(0);
}
function f() view {
Int.wrap(0) + Int.wrap(0);
}
function g() {
Int.wrap(0) + Int.wrap(0);
}
function h() pure {
Int.wrap(0) + Int.wrap(0);
}
// ----
// Warning 2018: (220-267): Function state mutability can be restricted to view
// TypeError 2527: (293-318): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".