diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-02-02 19:39:12 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-07-25 22:32:37 +0800 |
commit | e0dc74b895727525f261a9abe190872a58e8999e (patch) | |
tree | 67aa8cd1623c6afef8e24c04d8b220348313454b /test/libsolidity/Imports.cpp | |
parent | 7ad42aeeafe9f6d47ef5890add06b51d005b32ca (diff) | |
download | dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar.gz dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar.bz2 dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar.lz dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar.xz dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.tar.zst dexon-solidity-e0dc74b895727525f261a9abe190872a58e8999e.zip |
Warn about shadowing variables.
Diffstat (limited to 'test/libsolidity/Imports.cpp')
-rw-r--r-- | test/libsolidity/Imports.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 6aa96fb8..00f093b7 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -20,11 +20,15 @@ * Tests for high level features like import. */ -#include <string> -#include <boost/test/unit_test.hpp> +#include <test/libsolidity/ErrorCheck.h> + #include <libsolidity/interface/Exceptions.h> #include <libsolidity/interface/CompilerStack.h> +#include <boost/test/unit_test.hpp> + +#include <string> + using namespace std; namespace dev @@ -202,6 +206,67 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent) BOOST_CHECK(d.compile()); } +BOOST_AUTO_TEST_CASE(shadowing_via_import) +{ + CompilerStack c; + c.addSource("a", "library A {} pragma solidity >=0.0;"); + c.addSource("b", "library A {} pragma solidity >=0.0;"); + c.addSource("c", "import {A} from \"./a\"; import {A} from \"./b\";"); + BOOST_CHECK(!c.compile()); +} + +BOOST_AUTO_TEST_CASE(shadowing_builtins_with_imports) +{ + CompilerStack c; + c.addSource("B.sol", "contract X {} pragma solidity >=0.0;"); + c.addSource("b", R"( + pragma solidity >=0.0; + import * as msg from "B.sol"; + contract C { + } + )"); + BOOST_CHECK(c.compile()); + auto numErrors = c.errors().size(); + // Sometimes we get the prerelease warning, sometimes not. + BOOST_CHECK(2 <= numErrors && numErrors <= 3); + for (auto const& e: c.errors()) + { + string const* msg = e->comment(); + BOOST_REQUIRE(msg); + BOOST_CHECK( + msg->find("pre-release") != string::npos || + msg->find("shadows a builtin symbol") != string::npos + ); + } +} + +BOOST_AUTO_TEST_CASE(shadowing_builtins_with_multiple_imports) +{ + CompilerStack c; + c.addSource("B.sol", "contract msg {} contract block{} pragma solidity >=0.0;"); + c.addSource("b", R"( + pragma solidity >=0.0; + import {msg, block} from "B.sol"; + contract C { + } + )"); + BOOST_CHECK(c.compile()); + auto numErrors = c.errors().size(); + // Sometimes we get the prerelease warning, sometimes not. + BOOST_CHECK(4 <= numErrors && numErrors <= 5); + for (auto const& e: c.errors()) + { + string const* msg = e->comment(); + BOOST_REQUIRE(msg); + BOOST_CHECK( + msg->find("pre-release") != string::npos || + msg->find("shadows a builtin symbol") != string::npos + ); + } +} + + + BOOST_AUTO_TEST_SUITE_END() } |