From decfa0eed0512ec20aa15c3b7656f8369e9fdcba Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Feb 2018 10:58:50 +0100 Subject: Test aliasing in shadowing. --- test/libsolidity/Imports.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index 03287b28..dc1174f4 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -266,7 +266,28 @@ BOOST_AUTO_TEST_CASE(shadowing_builtins_with_multiple_imports) } } - +BOOST_AUTO_TEST_CASE(shadowing_builtins_with_alias) +{ + CompilerStack c; + c.addSource("B.sol", "contract C {} pragma solidity >=0.0;"); + c.addSource("b", R"( + pragma solidity >=0.0; + import {C as msg} from "B.sol"; + )"); + BOOST_CHECK(c.compile()); + auto numErrors = c.errors().size(); + // Sometimes we get the prerelease warning, sometimes not. + BOOST_CHECK(1 <= numErrors && numErrors <= 2); + 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() -- cgit From 4272d16f30e78d252e96b80f1202a61a06518a9f Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Feb 2018 11:03:56 +0100 Subject: Fix shadowing for imports with aliases. --- libsolidity/analysis/NameAndTypeResolver.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 5e4d414b..662792a3 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -457,9 +457,10 @@ bool DeclarationRegistrationHelper::registerDeclaration( if (!_errorLocation) _errorLocation = &_declaration.location(); + string name = _name ? *_name : _declaration.name(); Declaration const* shadowedDeclaration = nullptr; - if (_warnOnShadow && !_declaration.name().empty() && _container.enclosingContainer()) - for (auto const* decl: _container.enclosingContainer()->resolveName(_declaration.name(), true)) + if (_warnOnShadow && !name.empty() && _container.enclosingContainer()) + for (auto const* decl: _container.enclosingContainer()->resolveName(name, true)) shadowedDeclaration = decl; if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract())) -- cgit From 58bbb04276f27d3ecfa96dda54fbad80f8bbdbea Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Feb 2018 11:04:44 +0100 Subject: Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index d6b83d6e..4e6e1b92 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ Features: Bugfixes: * JSON-AST: Add "documentation" property to function, event and modifier definition. + * Resolver: Properly determine shadowing for imports with aliases. * Standard JSON: catch errors properly when invalid "sources" are passed * Type Checker: Properly warn when using ``_offset`` and ``_slot`` for constants in inline assembly. -- cgit