aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests/viewPureChecker
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-14 02:33:35 +0800
committerGitHub <noreply@github.com>2018-11-14 02:33:35 +0800
commit1d4f565a64988a3400847d2655ca24f73f234bc6 (patch)
treecaaa6c26e307513505349b50ca4f2a8a9506752b /test/libsolidity/syntaxTests/viewPureChecker
parent59dbf8f1085b8b92e8b7eb0ce380cbeb642e97eb (diff)
parent91b6b8a88e76016e0324036cb7a7f9300a1e2439 (diff)
downloaddexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.gz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.bz2
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.lz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.xz
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.tar.zst
dexon-solidity-1d4f565a64988a3400847d2655ca24f73f234bc6.zip
Merge pull request #5416 from ethereum/develop
Merge develop into release for 0.5.0
Diffstat (limited to 'test/libsolidity/syntaxTests/viewPureChecker')
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/assembly.sol23
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol20
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol21
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol27
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol10
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/constant.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol12
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol4
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/function_types.sol22
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol18
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/interface.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol19
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol15
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/mappings.sol12
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol17
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol12
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol16
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol7
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol8
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol13
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol14
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/selector.sol12
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol11
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol9
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol7
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol5
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol6
32 files changed, 382 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol b/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol
new file mode 100644
index 00000000..0a11dc3a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/assembly.sol
@@ -0,0 +1,23 @@
+contract C {
+ struct S { uint x; }
+ S s;
+ function e() pure public {
+ assembly { mstore(keccak256(0, 20), mul(s_slot, 2)) }
+ }
+ function f() pure public {
+ uint x;
+ assembly { x := 7 }
+ }
+ function g() view public {
+ assembly { for {} 1 { pop(sload(0)) } { } pop(gas) }
+ }
+ function h() view public {
+ assembly { function g() { pop(blockhash(20)) } }
+ }
+ function j() public {
+ assembly { pop(call(0, 1, 2, 3, 4, 5, 6)) }
+ }
+ function k() public {
+ assembly { pop(call(gas, 1, 2, 3, 4, 5, 6)) }
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol
new file mode 100644
index 00000000..2503a319
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol
@@ -0,0 +1,20 @@
+contract C {
+ function f() public {
+ address(this).transfer(1);
+ require(address(this).send(2));
+ selfdestruct(address(this));
+ (bool success,) = address(this).delegatecall("");
+ require(success);
+ (success,) = address(this).call("");
+ require(success);
+ }
+ function g() pure public {
+ bytes32 x = keccak256("abc");
+ bytes32 y = sha256("abc");
+ address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
+ require(true);
+ assert(true);
+ x; y; z;
+ }
+ function() payable external {}
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol
new file mode 100644
index 00000000..4a651d21
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_restrict_warning.sol
@@ -0,0 +1,21 @@
+contract C {
+ function f() view public {
+ bytes32 x = keccak256("abc");
+ bytes32 y = sha256("abc");
+ address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
+ require(true);
+ assert(true);
+ x; y; z;
+ }
+ function g() public {
+ bytes32 x = keccak256("abc");
+ bytes32 y = sha256("abc");
+ address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
+ require(true);
+ assert(true);
+ x; y; z;
+ }
+}
+// ----
+// Warning: (17-288): Function state mutability can be restricted to pure
+// Warning: (293-559): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol
new file mode 100644
index 00000000..5356f0b8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol
@@ -0,0 +1,27 @@
+contract C {
+ function f() view public {
+ address(this).transfer(1);
+ }
+ function g() view public {
+ require(address(this).send(2));
+ }
+ function h() view public {
+ selfdestruct(address(this));
+ }
+ function i() view public {
+ (bool success,) = address(this).delegatecall("");
+ require(success);
+ }
+ function j() view public {
+ (bool success,) = address(this).call("");
+ require(success);
+ }
+ function() payable external {
+ }
+}
+// ----
+// TypeError: (52-77): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
+// TypeError: (132-153): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
+// TypeError: (201-228): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
+// TypeError: (293-323): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
+// TypeError: (414-436): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol
new file mode 100644
index 00000000..e21037bd
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_fail.sol
@@ -0,0 +1,10 @@
+contract C {
+ uint x;
+ function f() pure public { g(); }
+ function g() view public { x; }
+ function h() view public { i(); }
+ function i() public { x = 2; }
+}
+// ----
+// TypeError: (56-59): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
+// TypeError: (130-133): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol
new file mode 100644
index 00000000..5aa21ce1
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol
@@ -0,0 +1,6 @@
+contract C {
+ function g() pure public { g(); }
+ function f() view public returns (uint) { f(); g(); }
+ function h() public { h(); g(); f(); }
+ function i() payable public { i(); h(); g(); f(); }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/constant.sol b/test/libsolidity/syntaxTests/viewPureChecker/constant.sol
new file mode 100644
index 00000000..36d93497
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/constant.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant x = 2;
+ function k() pure public returns (uint) {
+ return x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol
new file mode 100644
index 00000000..a4b4a353
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/constant_restrict_warning.sol
@@ -0,0 +1,12 @@
+contract C {
+ uint constant x = 2;
+ function f() view public returns (uint) {
+ return x;
+ }
+ function g() public returns (uint) {
+ return x;
+ }
+}
+// ----
+// Warning: (42-107): Function state mutability can be restricted to pure
+// Warning: (112-172): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol
new file mode 100644
index 00000000..d80edd1b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/creation_no_restrict_warning.sol
@@ -0,0 +1,4 @@
+contract D {}
+contract C {
+ function f() public { new D(); }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol
new file mode 100644
index 00000000..08e45ea1
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/creation_view_fail.sol
@@ -0,0 +1,6 @@
+contract D {}
+contract C {
+ function f() public view { new D(); }
+}
+// ----
+// TypeError: (58-65): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol b/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol
new file mode 100644
index 00000000..92943889
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/function_types.sol
@@ -0,0 +1,22 @@
+contract C {
+ function f() pure public {
+ function () external nonpayFun;
+ function () external view viewFun;
+ function () external pure pureFun;
+
+ nonpayFun;
+ viewFun;
+ pureFun;
+ pureFun();
+ }
+ function g() view public {
+ function () external view viewFun;
+
+ viewFun();
+ }
+ function h() public {
+ function () external nonpayFun;
+
+ nonpayFun();
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol
new file mode 100644
index 00000000..d00f65c9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/function_types_fail.sol
@@ -0,0 +1,18 @@
+contract C {
+ function f() pure public {
+ function () external nonpayFun;
+ nonpayFun();
+ }
+ function g() pure public {
+ function () external view viewFun;
+ viewFun();
+ }
+ function h() view public {
+ function () external nonpayFun;
+ nonpayFun();
+ }
+}
+// ----
+// TypeError: (92-103): Function declared as pure, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
+// TypeError: (193-202): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
+// TypeError: (289-300): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/interface.sol b/test/libsolidity/syntaxTests/viewPureChecker/interface.sol
new file mode 100644
index 00000000..0874e78a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/interface.sol
@@ -0,0 +1,6 @@
+interface D {
+ function f() view external;
+}
+contract C is D {
+ function f() view external {}
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol
new file mode 100644
index 00000000..7d01118a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables.sol
@@ -0,0 +1,19 @@
+contract C {
+ struct S { uint a; }
+ S s;
+ function f() view public {
+ S storage x = s;
+ x;
+ }
+ function g() view public {
+ S storage x = s;
+ x = s;
+ }
+ function i() public {
+ s.a = 2;
+ }
+ function h() public {
+ S storage x = s;
+ x.a = 2;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol
new file mode 100644
index 00000000..0ff1ac24
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/local_storage_variables_fail.sol
@@ -0,0 +1,15 @@
+contract C {
+ struct S { uint a; }
+ S s;
+ function f() pure public {
+ S storage x = s;
+ x;
+ }
+ function g() view public {
+ S storage x = s;
+ x.a = 1;
+ }
+}
+// ----
+// TypeError: (100-101): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
+// TypeError: (184-187): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol b/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol
new file mode 100644
index 00000000..eb0ccbfb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/mappings.sol
@@ -0,0 +1,12 @@
+contract C {
+ mapping(uint => uint) a;
+ function f() view public {
+ a;
+ }
+ function g() view public {
+ a[2];
+ }
+ function h() public {
+ a[2] = 3;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol b/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol
new file mode 100644
index 00000000..f8f6b2cb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/modifiers.sol
@@ -0,0 +1,17 @@
+contract D {
+ uint x;
+ modifier purem(uint) { _; }
+ modifier viewm(uint) { uint a = x; _; a; }
+ modifier nonpayablem(uint) { x = 2; _; }
+}
+contract C is D {
+ function f() purem(0) pure public {}
+ function g() viewm(0) view public {}
+ function h() nonpayablem(0) public {}
+ function i() purem(x) view public {}
+ function j() viewm(x) view public {}
+ function k() nonpayablem(x) public {}
+ function l() purem(x = 2) public {}
+ function m() viewm(x = 2) public {}
+ function n() nonpayablem(x = 2) public {}
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol
new file mode 100644
index 00000000..513850f7
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/modifiers_fail.sol
@@ -0,0 +1,12 @@
+contract D {
+ uint x;
+ modifier viewm(uint) { uint a = x; _; a; }
+ modifier nonpayablem(uint) { x = 2; _; }
+}
+contract C is D {
+ function f() viewm(0) pure public {}
+ function g() nonpayablem(0) view public {}
+}
+// ----
+// TypeError: (154-162): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
+// TypeError: (195-209): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol
new file mode 100644
index 00000000..160b20a7
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier m(uint _amount, uint _avail) { require(_avail >= _amount); _; }
+ function f() m(1 ether, msg.value) public pure {}
+}
+// ----
+// TypeError: (118-127): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol
new file mode 100644
index 00000000..613b0198
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier m(uint _amount, uint _avail) { require(_avail >= _amount); _; }
+ function f() m(1 ether, msg.value) public view {}
+}
+// ----
+// TypeError: (118-127): "msg.value" can only be used in payable public functions. Make the function "payable" or use an internal function to avoid this error.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol
new file mode 100644
index 00000000..61702495
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/overriding_fail.sol
@@ -0,0 +1,16 @@
+contract D {
+ uint x;
+ function f() public view { x; }
+ function g() public pure {}
+}
+contract C1 is D {
+ function f() public {}
+ function g() public view {}
+}
+contract C2 is D {
+ function g() public {}
+}
+// ----
+// TypeError: (118-140): Overriding function changes state mutability from "view" to "nonpayable".
+// TypeError: (145-172): Overriding function changes state mutability from "pure" to "view".
+// TypeError: (198-220): Overriding function changes state mutability from "pure" to "nonpayable".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol
new file mode 100644
index 00000000..c82c7908
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/overriding_no_restrict_warning.sol
@@ -0,0 +1,7 @@
+contract D {
+ uint x;
+ function f() public { x = 2; }
+}
+contract C is D {
+ function f() public {}
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol
new file mode 100644
index 00000000..785656b9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/read_storage_pure_fail.sol
@@ -0,0 +1,8 @@
+contract C {
+ uint x;
+ function f() public pure returns (uint) {
+ return x;
+ }
+}
+// ----
+// TypeError: (86-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol
new file mode 100644
index 00000000..e04d0825
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_fail.sol
@@ -0,0 +1,13 @@
+contract C {
+ struct S { uint x; }
+ S s;
+ function f() pure internal returns (S storage) {
+ return s;
+ }
+ function g() pure public {
+ f().x;
+ }
+}
+// ----
+// TypeError: (115-116): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
+// TypeError: (163-168): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol
new file mode 100644
index 00000000..9b4eb466
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/returning_structs_no_restrict_warning.sol
@@ -0,0 +1,14 @@
+contract C {
+ struct S { uint x; }
+ S s;
+ function f() view internal returns (S storage) {
+ return s;
+ }
+ function g() public {
+ f().x = 2;
+ }
+ function h() view public {
+ f();
+ f().x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector.sol
new file mode 100644
index 00000000..c4e30075
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/selector.sol
@@ -0,0 +1,12 @@
+contract C {
+ uint public x;
+ function f() payable public {
+ }
+ function g() pure public returns (bytes4) {
+ return this.f.selector ^ this.x.selector;
+ }
+ function h() view public returns (bytes4) {
+ x;
+ return this.f.selector ^ this.x.selector;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol
new file mode 100644
index 00000000..311dec4a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex.sol
@@ -0,0 +1,11 @@
+contract C {
+ function f(C c) pure public returns (C) {
+ return c;
+ }
+ function g() pure public returns (bytes4) {
+ // By passing `this`, we read from the state, even if f itself is pure.
+ return f(this).f.selector;
+ }
+}
+// ----
+// TypeError: (228-232): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol
new file mode 100644
index 00000000..d1543fed
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/selector_complex2.sol
@@ -0,0 +1,9 @@
+contract C {
+ function f() payable public returns (C) {
+ return this;
+ }
+ function g() pure public returns (bytes4) {
+ C x = C(0x123);
+ return x.f.selector;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol b/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol
new file mode 100644
index 00000000..0e397efc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/smoke_test.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint x;
+ function g() pure public {}
+ function f() view public returns (uint) { return now; }
+ function h() public { x = 2; }
+ function i() payable public { x = 2; }
+}
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol
new file mode 100644
index 00000000..87719eb3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/suggest_pure.sol
@@ -0,0 +1,5 @@
+contract C {
+ function g() view public { }
+}
+// ----
+// Warning: (17-45): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol
new file mode 100644
index 00000000..c045dfc4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/suggest_view.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint x;
+ function g() public returns (uint) { return x; }
+}
+// ----
+// Warning: (29-77): Function state mutability can be restricted to view
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol
new file mode 100644
index 00000000..3fed4d29
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/write_storage_fail.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint x;
+ function f() view public { x = 2; }
+}
+// ----
+// TypeError: (56-57): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.