From 6c4325ca034ea2d54f22c4f836f1101ab6721792 Mon Sep 17 00:00:00 2001 From: wechman Date: Wed, 13 Jul 2022 08:13:06 +0200 Subject: [PATCH] Add tests for ViewPureChecker with custom operators --- .../custom/operators_with_pure_modifier.sol | 26 ++++++++++++++++ .../custom/operators_with_view_modifier.sol | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/libsolidity/syntaxTests/operators/custom/operators_with_pure_modifier.sol create mode 100644 test/libsolidity/syntaxTests/operators/custom/operators_with_view_modifier.sol diff --git a/test/libsolidity/syntaxTests/operators/custom/operators_with_pure_modifier.sol b/test/libsolidity/syntaxTests/operators/custom/operators_with_pure_modifier.sol new file mode 100644 index 000000000..6a35cd78a --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operators_with_pure_modifier.sol @@ -0,0 +1,26 @@ +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". diff --git a/test/libsolidity/syntaxTests/operators/custom/operators_with_view_modifier.sol b/test/libsolidity/syntaxTests/operators/custom/operators_with_view_modifier.sol new file mode 100644 index 000000000..49493eda5 --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/operators_with_view_modifier.sol @@ -0,0 +1,30 @@ +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.