aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2019-01-09 02:33:46 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2019-01-10 17:36:50 +0800
commit0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc (patch)
tree8457ac70f7e9921d9825e939f2ff23ffc1259a46 /test
parent63319cfdcd7668a75caaacd0d8f3a83a62c31525 (diff)
downloaddexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.gz
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.bz2
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.lz
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.xz
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.zst
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.zip
Warn about unreachable code.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_err.sol4
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol1
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/always_revert.sol4
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/unreachable.sol1
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/comment_fine.sol6
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/constant_condition.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/do_while_continue.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_return.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_revert.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/for_break.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/if_both_return.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert_empty.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_break.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_continue.sol11
-rw-r--r--test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol2
-rw-r--r--test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol1
-rw-r--r--test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol2
-rw-r--r--test/libsolidity/syntaxTests/parsing/while_loop.sol1
19 files changed, 120 insertions, 1 deletions
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_err.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_err.sol
index b868d61d..c7e3eacd 100644
--- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_err.sol
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_err.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol
index 55c5edd3..5a113668 100644
--- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol
@@ -29,3 +29,4 @@ contract C {
}
}
// ----
+// Warning: (567-572): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/always_revert.sol b/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/always_revert.sol
index 96767402..da7f1a90 100644
--- a/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/always_revert.sol
+++ b/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/always_revert.sol
@@ -5,4 +5,6 @@ contract C {
revert();
b;
}
-} \ No newline at end of file
+}
+// ----
+// Warning: (125-126): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/unreachable.sol b/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/unreachable.sol
index b941ad34..9ebd0321 100644
--- a/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/unreachable.sol
+++ b/test/libsolidity/syntaxTests/controlFlow/uninitializedAccess/unreachable.sol
@@ -8,3 +8,4 @@ contract C {
}
}
// ----
+// Warning: (112-135): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/comment_fine.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/comment_fine.sol
new file mode 100644
index 00000000..17119ca6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/comment_fine.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() public pure {
+ return;
+ // unreachable comment
+ }
+}
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/constant_condition.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/constant_condition.sol
new file mode 100644
index 00000000..e00398bc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/constant_condition.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public pure {
+ if (false) {
+ return; // unreachable, but not yet detected
+ }
+ return;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/do_while_continue.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/do_while_continue.sol
new file mode 100644
index 00000000..363c53e1
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/do_while_continue.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_return.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_return.sol
new file mode 100644
index 00000000..9b755347
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_return.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public pure returns (uint) {
+ return 0;
+ return 0;
+ }
+}
+// ----
+// Warning: (85-93): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_revert.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_revert.sol
new file mode 100644
index 00000000..a6457e4f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/double_revert.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public pure {
+ revert();
+ revert();
+ }
+}
+// ----
+// Warning: (70-78): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/for_break.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/for_break.sol
new file mode 100644
index 00000000..496addb2
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/for_break.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/if_both_return.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/if_both_return.sol
new file mode 100644
index 00000000..3513b17d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/if_both_return.sol
@@ -0,0 +1,12 @@
+contract C {
+ function f(bool c) public pure {
+ if (c) {
+ return;
+ } else {
+ return;
+ }
+ return; // unreachable
+ }
+}
+// ----
+// Warning: (142-149): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert.sol
new file mode 100644
index 00000000..9bb6a41c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public pure {
+ revert();
+ uint a = 0; a;
+ }
+}
+// ----
+// Warning: (70-83): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert_empty.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert_empty.sol
new file mode 100644
index 00000000..4c80c5ca
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/revert_empty.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public pure {
+ revert();
+ for(int i = 0; i < 3; i++) { f(); }
+ }
+}
+// ----
+// Warning: (70-105): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_break.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_break.sol
new file mode 100644
index 00000000..2d1ddd4f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_break.sol
@@ -0,0 +1,12 @@
+contract C {
+ function f() public pure {
+ uint a = 0;
+ while (a < 100) {
+ a++;
+ break;
+ a--;
+ }
+ }
+}
+// ----
+// Warning: (138-141): Unreachable code.
diff --git a/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_continue.sol b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_continue.sol
new file mode 100644
index 00000000..55f98f67
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/unreachableCode/while_continue.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol
index fce669dd..9fafd706 100644
--- a/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol
+++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol
@@ -7,6 +7,8 @@ contract test {
}
}
// ----
+// Warning: (103-106): Unreachable code.
+// Warning: (144-152): Unreachable code.
// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (122-131): Unused local variable.
// Warning: (20-169): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol
index 4adf0948..c36f9c58 100644
--- a/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol
+++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol
@@ -7,6 +7,7 @@ contract test {
}
}
// ----
+// Warning: (144-152): Unreachable code.
// Warning: (37-46): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (122-131): Unused local variable.
// Warning: (24-177): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol
index c22ae42f..c81f611b 100644
--- a/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol
+++ b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol
@@ -6,6 +6,8 @@ contract test {
}
}
// ----
+// Warning: (89-92): Unreachable code.
+// Warning: (130-138): Unreachable code.
// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (108-117): Unused local variable.
// Warning: (20-155): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/parsing/while_loop.sol b/test/libsolidity/syntaxTests/parsing/while_loop.sol
index dbb00a69..cdac929f 100644
--- a/test/libsolidity/syntaxTests/parsing/while_loop.sol
+++ b/test/libsolidity/syntaxTests/parsing/while_loop.sol
@@ -5,3 +5,4 @@ contract test {
}
}
// ----
+// Warning: (105-113): Unreachable code.