aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp20
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp66
-rw-r--r--test/libsolidity/SolidityParser.cpp34
-rw-r--r--test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol6
-rw-r--r--test/libsolidity/syntaxTests/constants/assign_constant_function_value_050.sol8
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_fine.sol26
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_warn.sol10
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol19
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol36
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol35
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_fine.sol6
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_warn.sol15
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/for_fine.sol13
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/for_warn.sol16
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/if_fine.sol29
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/if_warn.sol18
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_fine.sol20
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_warn.sol22
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/revert_fine.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_fine.sol11
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_warn.sol18
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/smoke.sol10
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_fine.sol14
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_warn.sol13
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/throw_fine.sol9
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/tuple_fine.sol12
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/while_fine.sol19
-rw-r--r--test/libsolidity/syntaxTests/controlFlow/storageReturn/while_warn.sol11
-rw-r--r--test/libsolidity/syntaxTests/fallback/pure_modifier.sol6
-rw-r--r--test/libsolidity/syntaxTests/fallback/view_modifier.sol6
-rw-r--r--test/libsolidity/syntaxTests/inheritance/override/add_view.sol4
-rw-r--r--test/libsolidity/syntaxTests/inheritance/override/remove_view.sol4
-rw-r--r--test/libsolidity/syntaxTests/missing_state_variable.sol7
-rw-r--r--test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol7
-rw-r--r--test/libsolidity/syntaxTests/parsing/empty_function.sol8
-rw-r--r--test/libsolidity/syntaxTests/parsing/multiple_statemutability_specifiers.sol33
36 files changed, 489 insertions, 114 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index dd82a05c..2db2aadd 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2105,7 +2105,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
char const* sourceCode = R"(
contract test {
uint120[3] x;
- function f() view returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
+ function f() returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
uint120[] memory y = new uint120[](3);
x[0] = y[0] = uint120(-2);
x[1] = y[1] = uint120(-3);
@@ -10917,9 +10917,9 @@ BOOST_AUTO_TEST_CASE(negative_stack_height)
bool Aboolc;
bool exists;
}
- function nredit(uint startindex) public constant returns(uint[500] CIDs, uint[500] dates, uint[500] RIDs, bool[500] Cboolas, uint[500] amounts){}
- function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public constant returns(uint[500] AIDs, bool[500] Aboolas, uint[500] dates, bytes32[3][500] Abytesas, bytes32[3][500] bytesbs, bytes32[2][500] bytescs, uint[500] amounts, bool[500] Aboolbs, bool[500] Aboolcs){}
- function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public constant returns(uint[500] BIDs, uint[500] dates, uint[500] RIDs, bool[500] Bboolas, bytes32[3][500] bytesbs,bytes32[2][500] bytescs, uint[500] amounts, bool[500] Bboolbs){}
+ function nredit(uint startindex) public pure returns(uint[500] CIDs, uint[500] dates, uint[500] RIDs, bool[500] Cboolas, uint[500] amounts){}
+ function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] AIDs, bool[500] Aboolas, uint[500] dates, bytes32[3][500] Abytesas, bytes32[3][500] bytesbs, bytes32[2][500] bytescs, uint[500] amounts, bool[500] Aboolbs, bool[500] Aboolcs){}
+ function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] BIDs, uint[500] dates, uint[500] RIDs, bool[500] Bboolas, bytes32[3][500] bytesbs,bytes32[2][500] bytescs, uint[500] amounts, bool[500] Bboolbs){}
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -11105,13 +11105,13 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address)
char const* sourceCode = R"(
contract C {
/// Calling into non-existant account is successful (creates the account)
- function f() external view returns (bool) {
+ function f() external returns (bool) {
return address(0x4242).call();
}
- function g() external view returns (bool) {
+ function g() external returns (bool) {
return address(0x4242).callcode();
}
- function h() external view returns (bool) {
+ function h() external returns (bool) {
return address(0x4242).delegatecall();
}
}
@@ -11133,13 +11133,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value)
function get() external view returns (uint) {
return value;
}
- function get_delegated() external view returns (bool) {
+ function get_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("get()")));
}
function assert0() external view {
assert(value == 0);
}
- function assert0_delegated() external view returns (bool) {
+ function assert0_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("assert0()")));
}
}
@@ -11600,7 +11600,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_v2)
require(y[0] == "e");
}
S s;
- function f4() public view returns (bytes r) {
+ function f4() public returns (bytes r) {
string memory x = "abc";
s.a = 7;
s.b.push(2);
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 91fd1fff..5af67659 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -831,24 +831,6 @@ BOOST_AUTO_TEST_CASE(illegal_override_visibility)
CHECK_ERROR(text, TypeError, "Overriding function visibility differs");
}
-BOOST_AUTO_TEST_CASE(illegal_override_remove_constness)
-{
- char const* text = R"(
- contract B { function f() constant {} }
- contract C is B { function f() public {} }
- )";
- CHECK_ERROR(text, TypeError, "Overriding function changes state mutability from \"view\" to \"nonpayable\".");
-}
-
-BOOST_AUTO_TEST_CASE(illegal_override_add_constness)
-{
- char const* text = R"(
- contract B { function f() public {} }
- contract C is B { function f() constant {} }
- )";
- CHECK_ERROR(text, TypeError, "Overriding function changes state mutability from \"nonpayable\" to \"view\".");
-}
-
BOOST_AUTO_TEST_CASE(complex_inheritance)
{
char const* text = R"(
@@ -993,19 +975,6 @@ BOOST_AUTO_TEST_CASE(private_state_variable)
BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of an internal variable should not exist");
}
-BOOST_AUTO_TEST_CASE(missing_state_variable)
-{
- char const* text = R"(
- contract Scope {
- function getStateVar() constant public returns (uint stateVar) {
- stateVar = Scope.stateVar; // should fail.
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Member \"stateVar\" not found or not visible after argument-dependent lookup in type(contract Scope)");
-}
-
-
BOOST_AUTO_TEST_CASE(base_class_state_variable_accessor)
{
// test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126
@@ -1119,17 +1088,6 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters)
CHECK_ERROR(text, TypeError, "Fallback function cannot return values.");
}
-BOOST_AUTO_TEST_CASE(fallback_function_with_constant_modifier)
-{
- char const* text = R"(
- contract C {
- uint x;
- function() constant { x = 2; }
- }
- )";
- CHECK_ERROR(text, TypeError, "Fallback function must be payable or non-payable");
-}
-
BOOST_AUTO_TEST_CASE(fallback_function_twice)
{
char const* text = R"(
@@ -2327,30 +2285,6 @@ BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment)
CHECK_ERROR(text, TypeError, "Index access for string is not possible.");
}
-BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant_0_4_x)
-{
- char const* text = R"(
- contract C {
- function () constant returns (uint) x;
- uint constant y = x();
- }
- )";
- CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant.");
-}
-
-BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant)
-{
- char const* text = R"(
- pragma experimental "v0.5.0";
-
- contract C {
- function () constant returns (uint) x;
- uint constant y = x();
- }
- )";
- CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant.");
-}
-
BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_conversion)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 77686b03..cbea8694 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -838,40 +838,6 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers)
CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\".");
}
-BOOST_AUTO_TEST_CASE(multiple_statemutability_specifiers)
-{
- char const* text = R"(
- contract c {
- function f() payable payable {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"payable\".");
- text = R"(
- contract c {
- function f() constant constant {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\".");
- text = R"(
- contract c {
- function f() constant view {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"view\".");
- text = R"(
- contract c {
- function f() payable constant {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"payable\".");
- text = R"(
- contract c {
- function f() pure payable {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"pure\".");
- text = R"(
- contract c {
- function f() pure constant {}
- })";
- CHECK_PARSE_ERROR(text, "State mutability already specified as \"pure\".");
-}
-
BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations)
{
char const* text = R"(
diff --git a/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol
new file mode 100644
index 00000000..88e94e29
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol
@@ -0,0 +1,6 @@
+contract C {
+ function () pure returns (uint) x;
+ uint constant y = x();
+}
+// ----
+// Warning: (74-77): Initial value for constant variable has to be compile-time constant. This will fail to compile with the next breaking version change.
diff --git a/test/libsolidity/syntaxTests/constants/assign_constant_function_value_050.sol b/test/libsolidity/syntaxTests/constants/assign_constant_function_value_050.sol
new file mode 100644
index 00000000..2c92899d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/assign_constant_function_value_050.sol
@@ -0,0 +1,8 @@
+pragma experimental "v0.5.0";
+
+contract C {
+ function () pure returns (uint) x;
+ uint constant y = x();
+}
+// ----
+// TypeError: (105-108): Initial value for constant variable has to be compile-time constant.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_fine.sol
new file mode 100644
index 00000000..65902cc8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_fine.sol
@@ -0,0 +1,26 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal returns (S storage c) {
+ assembly {
+ sstore(c_slot, sload(s_slot))
+ }
+ }
+ function g(bool flag) internal returns (S storage c) {
+ // control flow in assembly will not be analyzed for now,
+ // so this will not issue a warning
+ assembly {
+ if flag {
+ sstore(c_slot, sload(s_slot))
+ }
+ }
+ }
+ function h() internal returns (S storage c) {
+ // any reference from assembly will be sufficient for now,
+ // so this will not issue a warning
+ assembly {
+ sstore(s_slot, sload(c_slot))
+ }
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_warn.sol
new file mode 100644
index 00000000..09c13847
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly_warn.sol
@@ -0,0 +1,10 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal pure returns (S storage) {
+ assembly {
+ }
+ }
+}
+// ----
+// Warning: (87-88): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol
new file mode 100644
index 00000000..9a42192d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol
@@ -0,0 +1,19 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S c) {
+ c = s;
+ }
+ function g() internal view returns (S) {
+ return s;
+ }
+ function h() internal pure returns (S) {
+ }
+ function i(bool flag) internal view returns (S c) {
+ if (flag) c = s;
+ }
+ function j(bool flag) internal view returns (S) {
+ if (flag) return s;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol
new file mode 100644
index 00000000..6520672c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol
@@ -0,0 +1,36 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ do {} while((c = s).f);
+ }
+ function g() internal view returns (S storage c) {
+ do { c = s; } while(false);
+ }
+ function h() internal view returns (S storage c) {
+ c = s;
+ do {} while(false);
+ }
+ function i() internal view returns (S storage c) {
+ do {} while(false);
+ c = s;
+ }
+ function j() internal view returns (S storage c) {
+ do {
+ c = s;
+ break;
+ } while(false);
+ }
+ function k() internal view returns (S storage c) {
+ do {
+ if (s.f) {
+ continue;
+ break;
+ }
+ else {
+ c = s;
+ }
+ } while(false);
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol
new file mode 100644
index 00000000..f1a92e9c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol
@@ -0,0 +1,35 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ do {
+ break;
+ c = s;
+ } while(false);
+ }
+ function g() internal view returns (S storage c) {
+ do {
+ if (s.f) {
+ continue;
+ c = s;
+ }
+ else {
+ }
+ } while(false);
+ }
+ function h() internal view returns (S storage c) {
+ do {
+ if (s.f) {
+ break;
+ continue;
+ }
+ else {
+ c = s;
+ }
+ } while(false);
+ }
+}
+// ----
+// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (223-234): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (440-451): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_fine.sol
new file mode 100644
index 00000000..3a0a30ea
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_fine.sol
@@ -0,0 +1,6 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c, S storage d) { c = s; d = s; return; }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_warn.sol
new file mode 100644
index 00000000..0a5b2fbf
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/emptyReturn_warn.sol
@@ -0,0 +1,15 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal pure returns (S storage) { return; }
+ function g() internal view returns (S storage c, S storage) { c = s; return; }
+ function h() internal view returns (S storage, S storage d) { d = s; return; }
+ function i() internal pure returns (S storage, S storage) { return; }
+ function j() internal view returns (S storage, S storage) { return (s,s); }
+}
+// ----
+// Warning: (87-88): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (163-164): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (233-234): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (316-317): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (327-328): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_fine.sol
new file mode 100644
index 00000000..aa82cb9a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_fine.sol
@@ -0,0 +1,13 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ for(c = s;;) {
+ }
+ }
+ function g() internal view returns (S storage c) {
+ for(; (c = s).f;) {
+ }
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_warn.sol
new file mode 100644
index 00000000..ba9a2440
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/for_warn.sol
@@ -0,0 +1,16 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ for(;; c = s) {
+ }
+ }
+ function g() internal view returns (S storage c) {
+ for(;;) {
+ c = s;
+ }
+ }
+}
+// ----
+// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (182-193): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_fine.sol
new file mode 100644
index 00000000..b809e95d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_fine.sol
@@ -0,0 +1,29 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f(bool flag) internal view returns (S storage c) {
+ if (flag) c = s;
+ else c = s;
+ }
+ function g(bool flag) internal view returns (S storage c) {
+ if (flag) c = s;
+ else { c = s; }
+ }
+ function h(bool flag) internal view returns (S storage c) {
+ if (flag) c = s;
+ else
+ {
+ if (!flag) c = s;
+ else c = s;
+ }
+ }
+ function i() internal view returns (S storage c) {
+ if ((c = s).f) {
+ }
+ }
+ function j() internal view returns (S storage c) {
+ if ((c = s).f && !(c = s).f) {
+ }
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_warn.sol
new file mode 100644
index 00000000..c257c252
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/if_warn.sol
@@ -0,0 +1,18 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f(bool flag) internal view returns (S storage c) {
+ if (flag) c = s;
+ }
+ function g(bool flag) internal returns (S storage c) {
+ if (flag) c = s;
+ else
+ {
+ if (!flag) c = s;
+ else s.f = true;
+ }
+ }
+}
+// ----
+// Warning: (96-107): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (186-197): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_fine.sol
new file mode 100644
index 00000000..ee37f6d6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_fine.sol
@@ -0,0 +1,20 @@
+contract C {
+ modifier revertIfNoReturn() {
+ _;
+ revert();
+ }
+ modifier ifFlag(bool flag) {
+ if (flag)
+ _;
+ }
+ struct S { uint a; }
+ S s;
+ function f(bool flag) revertIfNoReturn() internal view returns(S storage) {
+ if (flag) return s;
+ }
+ function g(bool flag) revertIfNoReturn() ifFlag(flag) internal view returns(S storage) {
+ return s;
+ }
+
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_warn.sol
new file mode 100644
index 00000000..50c6dd99
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/modifier_warn.sol
@@ -0,0 +1,22 @@
+contract C {
+ modifier revertIfNoReturn() {
+ _;
+ revert();
+ }
+ modifier ifFlag(bool flag) {
+ if (flag)
+ _;
+ }
+ struct S { uint a; }
+ S s;
+ function f(bool flag) ifFlag(flag) internal view returns(S storage) {
+ return s;
+ }
+
+ function g(bool flag) ifFlag(flag) revertIfNoReturn() internal view returns(S storage) {
+ return s;
+ }
+}
+// ----
+// Warning: (249-250): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (367-368): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/revert_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/revert_fine.sol
new file mode 100644
index 00000000..022f2d1c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/revert_fine.sol
@@ -0,0 +1,12 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal pure returns (S storage) {
+ revert();
+ }
+ function g(bool flag) internal view returns (S storage c) {
+ if (flag) c = s;
+ else revert();
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_fine.sol
new file mode 100644
index 00000000..699849c0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_fine.sol
@@ -0,0 +1,11 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ (c = s).f && false;
+ }
+ function g() internal view returns (S storage c) {
+ (c = s).f || true;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_warn.sol
new file mode 100644
index 00000000..9f660f11
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/short_circuit_warn.sol
@@ -0,0 +1,18 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ false && (c = s).f;
+ }
+ function g() internal view returns (S storage c) {
+ true || (c = s).f;
+ }
+ function h() internal view returns (S storage c) {
+ // expect warning, although this is always fine
+ true && (false || (c = s).f);
+ }
+}
+// ----
+// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (176-187): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (264-275): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/smoke.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/smoke.sol
new file mode 100644
index 00000000..beeadbe4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/smoke.sol
@@ -0,0 +1,10 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal pure {}
+ function g() internal view returns (S storage) { return s; }
+ function h() internal view returns (S storage c) { return s; }
+ function i() internal view returns (S storage c) { c = s; }
+ function j() internal view returns (S storage c) { (c) = s; }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_fine.sol
new file mode 100644
index 00000000..ee3869bd
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_fine.sol
@@ -0,0 +1,14 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f(bool flag) internal view returns (S storage c) {
+ flag ? c = s : c = s;
+ }
+ function g(bool flag) internal view returns (S storage c) {
+ flag ? c = s : (c = s);
+ }
+ function h(bool flag) internal view returns (S storage c) {
+ flag ? (c = s).f : (c = s).f;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_warn.sol
new file mode 100644
index 00000000..57561fbb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/ternary_warn.sol
@@ -0,0 +1,13 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f(bool flag) internal view returns (S storage c) {
+ flag ? (c = s).f : false;
+ }
+ function g(bool flag) internal view returns (S storage c) {
+ flag ? false : (c = s).f;
+ }
+}
+// ----
+// Warning: (96-107): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
+// Warning: (200-211): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/throw_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/throw_fine.sol
new file mode 100644
index 00000000..4cecc27c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/throw_fine.sol
@@ -0,0 +1,9 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal pure returns (S storage) {
+ throw;
+ }
+}
+// ----
+// Warning: (108-113): "throw" is deprecated in favour of "revert()", "require()" and "assert()".
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/tuple_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/tuple_fine.sol
new file mode 100644
index 00000000..0b171560
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/tuple_fine.sol
@@ -0,0 +1,12 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage, uint) {
+ return (s,2);
+ }
+ function g() internal view returns (S storage c) {
+ uint a;
+ (c, a) = f();
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_fine.sol
new file mode 100644
index 00000000..71543422
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_fine.sol
@@ -0,0 +1,19 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ while((c = s).f) {
+ }
+ }
+ function g() internal view returns (S storage c) {
+ c = s;
+ while(false) {
+ }
+ }
+ function h() internal view returns (S storage c) {
+ while(false) {
+ }
+ c = s;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_warn.sol
new file mode 100644
index 00000000..26db892f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/while_warn.sol
@@ -0,0 +1,11 @@
+contract C {
+ struct S { bool f; }
+ S s;
+ function f() internal view returns (S storage c) {
+ while(false) {
+ c = s;
+ }
+ }
+}
+// ----
+// Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/fallback/pure_modifier.sol b/test/libsolidity/syntaxTests/fallback/pure_modifier.sol
new file mode 100644
index 00000000..20d5b0ac
--- /dev/null
+++ b/test/libsolidity/syntaxTests/fallback/pure_modifier.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint x;
+ function() pure { x = 2; }
+}
+// ----
+// TypeError: (29-55): Fallback function must be payable or non-payable, but is "pure".
diff --git a/test/libsolidity/syntaxTests/fallback/view_modifier.sol b/test/libsolidity/syntaxTests/fallback/view_modifier.sol
new file mode 100644
index 00000000..44c5d204
--- /dev/null
+++ b/test/libsolidity/syntaxTests/fallback/view_modifier.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint x;
+ function() view { x = 2; }
+}
+// ----
+// TypeError: (29-55): Fallback function must be payable or non-payable, but is "view".
diff --git a/test/libsolidity/syntaxTests/inheritance/override/add_view.sol b/test/libsolidity/syntaxTests/inheritance/override/add_view.sol
new file mode 100644
index 00000000..9973b23e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/override/add_view.sol
@@ -0,0 +1,4 @@
+contract B { function f() public {} }
+contract C is B { function f() view {} }
+// ----
+// TypeError: (56-76): Overriding function changes state mutability from "nonpayable" to "view".
diff --git a/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol b/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol
new file mode 100644
index 00000000..e58f6b20
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/override/remove_view.sol
@@ -0,0 +1,4 @@
+contract B { function f() view {} }
+contract C is B { function f() public {} }
+// ----
+// TypeError: (54-76): Overriding function changes state mutability from "view" to "nonpayable".
diff --git a/test/libsolidity/syntaxTests/missing_state_variable.sol b/test/libsolidity/syntaxTests/missing_state_variable.sol
new file mode 100644
index 00000000..02082a45
--- /dev/null
+++ b/test/libsolidity/syntaxTests/missing_state_variable.sol
@@ -0,0 +1,7 @@
+contract Scope {
+ function getStateVar() view public returns (uint stateVar) {
+ stateVar = Scope.stateVar; // should fail.
+ }
+}
+// ----
+// TypeError: (101-115): Member "stateVar" not found or not visible after argument-dependent lookup in type(contract Scope)
diff --git a/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol b/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol
new file mode 100644
index 00000000..da068351
--- /dev/null
+++ b/test/libsolidity/syntaxTests/parsing/constant_state_modifier.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint s;
+ // this test should fail starting from 0.5.0
+ function f() public constant returns (uint) {
+ return s;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/parsing/empty_function.sol b/test/libsolidity/syntaxTests/parsing/empty_function.sol
index 4f845189..218fd9a7 100644
--- a/test/libsolidity/syntaxTests/parsing/empty_function.sol
+++ b/test/libsolidity/syntaxTests/parsing/empty_function.sol
@@ -1,10 +1,10 @@
contract test {
uint256 stateVar;
- function functionName(bytes20 arg1, address addr) constant returns (int id) { }
+ function functionName(bytes20 arg1, address addr) view returns (int id) { }
}
// ----
-// Warning: (36-115): No visibility specified. Defaulting to "public".
+// Warning: (36-111): No visibility specified. Defaulting to "public".
// Warning: (58-70): Unused function parameter. Remove or comment out the variable name to silence this warning.
// Warning: (72-84): Unused function parameter. Remove or comment out the variable name to silence this warning.
-// Warning: (104-110): Unused function parameter. Remove or comment out the variable name to silence this warning.
-// Warning: (36-115): Function state mutability can be restricted to pure
+// Warning: (100-106): Unused function parameter. Remove or comment out the variable name to silence this warning.
+// Warning: (36-111): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/parsing/multiple_statemutability_specifiers.sol b/test/libsolidity/syntaxTests/parsing/multiple_statemutability_specifiers.sol
new file mode 100644
index 00000000..a05bf452
--- /dev/null
+++ b/test/libsolidity/syntaxTests/parsing/multiple_statemutability_specifiers.sol
@@ -0,0 +1,33 @@
+contract c1 {
+ function f() payable payable {}
+}
+contract c2 {
+ function f() view view {}
+}
+contract c3 {
+ function f() pure pure {}
+}
+contract c4 {
+ function f() pure view {}
+}
+contract c5 {
+ function f() payable view {}
+}
+contract c6 {
+ function f() pure payable {}
+}
+contract c7 {
+ function f() pure constant {}
+}
+contract c8 {
+ function f() view constant {}
+}
+// ----
+// ParserError: (39-46): State mutability already specified as "payable".
+// ParserError: (88-92): State mutability already specified as "view".
+// ParserError: (134-138): State mutability already specified as "pure".
+// ParserError: (180-184): State mutability already specified as "pure".
+// ParserError: (229-233): State mutability already specified as "payable".
+// ParserError: (275-282): State mutability already specified as "pure".
+// ParserError: (324-332): State mutability already specified as "pure".
+// ParserError: (374-382): State mutability already specified as "view".