mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Warn about unreachable code.
This commit is contained in:
@@ -46,7 +46,11 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// TypeError: (87-98): This variable is of storage pointer type and can be returned without prior assignment.
|
||||
// Warning: (146-151): Unreachable code.
|
||||
// Warning: (169-174): Unreachable code.
|
||||
// TypeError: (223-234): This variable is of storage pointer type and can be returned without prior assignment.
|
||||
// Warning: (316-321): Unreachable code.
|
||||
// TypeError: (440-451): This variable is of storage pointer type and can be returned without prior assignment.
|
||||
// TypeError: (654-665): This variable is of storage pointer type and can be returned without prior assignment.
|
||||
// TypeError: (871-882): This variable is of storage pointer type and can be returned without prior assignment.
|
||||
// Warning: (933-938): Unreachable code.
|
||||
|
||||
@@ -29,3 +29,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (567-572): Unreachable code.
|
||||
|
||||
@@ -5,4 +5,6 @@ contract C {
|
||||
revert();
|
||||
b;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (125-126): Unreachable code.
|
||||
|
||||
@@ -8,3 +8,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (112-135): Unreachable code.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
return;
|
||||
// unreachable comment
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
if (false) {
|
||||
return; // unreachable, but not yet detected
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
do {
|
||||
uint a = 42; a;
|
||||
continue;
|
||||
return; // this is unreachable
|
||||
} while(false);
|
||||
return; // this is still reachable
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (119-126): Unreachable code.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure returns (uint) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (85-93): Unreachable code.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert();
|
||||
revert();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (70-78): Unreachable code.
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
for (uint a = 0; a < 1; a++) {
|
||||
break;
|
||||
uint b = 42; b;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (76-79): Unreachable code.
|
||||
// Warning: (114-128): Unreachable code.
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f(bool c) public pure {
|
||||
if (c) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
return; // unreachable
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (142-149): Unreachable code.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert();
|
||||
uint a = 0; a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (70-83): Unreachable code.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
revert();
|
||||
for(int i = 0; i < 3; i++) { f(); }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (70-105): Unreachable code.
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
uint a = 0;
|
||||
while (a < 100) {
|
||||
a++;
|
||||
break;
|
||||
a--;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (138-141): Unreachable code.
|
||||
@@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
while(true) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
return; // this is unreachable as well, but currently undetected (needs to consider constant condition "true")
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (100-107): Unreachable code.
|
||||
Reference in New Issue
Block a user