mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add control flow tests for "and" and "or" operators
This commit is contained in:
parent
43a612e420
commit
1084a34f28
@ -57,6 +57,7 @@ unique_ptr<FunctionFlow> ControlFlowBuilder::createFunctionFlow(
|
||||
bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
||||
{
|
||||
solAssert(!!m_currentNode, "");
|
||||
visitNode(_operation);
|
||||
|
||||
switch (_operation.getOperator())
|
||||
{
|
||||
@ -65,7 +66,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
||||
{
|
||||
visitNode(_operation);
|
||||
solAssert(!_operation.annotation().userDefinedFunction);
|
||||
visitNode(_operation);
|
||||
appendControlFlow(_operation.leftExpression());
|
||||
|
||||
auto nodes = splitFlow<2>();
|
||||
@ -76,7 +76,6 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation)
|
||||
}
|
||||
default:
|
||||
{
|
||||
visitNode(_operation);
|
||||
if (_operation.annotation().userDefinedFunction)
|
||||
{
|
||||
visitNode(_operation);
|
||||
|
@ -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.
|
@ -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.
|
@ -2,16 +2,25 @@ struct S { bool f; }
|
||||
|
||||
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 {
|
||||
S s;
|
||||
function f() public {
|
||||
S storage x = s;
|
||||
S storage y;
|
||||
x + y;
|
||||
function get() private returns (S storage) {
|
||||
S storage s;
|
||||
return s;
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -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".
|
@ -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.
|
@ -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
|
@ -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".
|
Loading…
Reference in New Issue
Block a user