diff options
author | chriseth <chris@ethereum.org> | 2018-02-13 16:49:50 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-02-13 18:00:59 +0800 |
commit | 5916cf1e0ace5d9855af4d785c22c742cf106b8a (patch) | |
tree | 086046177d246cbdec3e8907445dff0e36bca24a /test/libsolidity/ViewPureChecker.cpp | |
parent | 729c6a95f8615586969e206b0b796011b3824adf (diff) | |
download | dexon-solidity-5916cf1e0ace5d9855af4d785c22c742cf106b8a.tar.gz dexon-solidity-5916cf1e0ace5d9855af4d785c22c742cf106b8a.tar.zst dexon-solidity-5916cf1e0ace5d9855af4d785c22c742cf106b8a.zip |
Allow `this.f.selector` to be pure.
Diffstat (limited to 'test/libsolidity/ViewPureChecker.cpp')
-rw-r--r-- | test/libsolidity/ViewPureChecker.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index e91e713c..0fee95c5 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -326,6 +326,52 @@ BOOST_AUTO_TEST_CASE(function_types) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(selector) +{ + string text = R"( + contract C { + function f() payable public { + } + function g() pure public returns (bytes4) { + return this.f.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + +BOOST_AUTO_TEST_CASE(selector_complex) +{ + string text = R"( + 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; + } + } + )"; + CHECK_ERROR(text, TypeError, "reads from the environment or state and thus requires \"view\""); +} + +BOOST_AUTO_TEST_CASE(selector_complex2) +{ + string text = R"( + contract C { + function f() payable public returns (C) { + return this; + } + function g() pure public returns (bytes4) { + C x = C(0x123); + return x.f.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + BOOST_AUTO_TEST_CASE(creation) { string text = R"( |