mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3535 from ethereum/fixShadowing
Fix shadowing detection for aliases
This commit is contained in:
commit
f5f00b4ee9
@ -7,6 +7,7 @@ Features:
|
|||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* JSON-AST: Add "documentation" property to function, event and modifier definition.
|
* 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
|
* Standard JSON: catch errors properly when invalid "sources" are passed
|
||||||
* Type Checker: Properly warn when using ``_offset`` and ``_slot`` for constants in inline assembly.
|
* Type Checker: Properly warn when using ``_offset`` and ``_slot`` for constants in inline assembly.
|
||||||
|
|
||||||
|
@ -457,9 +457,10 @@ bool DeclarationRegistrationHelper::registerDeclaration(
|
|||||||
if (!_errorLocation)
|
if (!_errorLocation)
|
||||||
_errorLocation = &_declaration.location();
|
_errorLocation = &_declaration.location();
|
||||||
|
|
||||||
|
string name = _name ? *_name : _declaration.name();
|
||||||
Declaration const* shadowedDeclaration = nullptr;
|
Declaration const* shadowedDeclaration = nullptr;
|
||||||
if (_warnOnShadow && !_declaration.name().empty() && _container.enclosingContainer())
|
if (_warnOnShadow && !name.empty() && _container.enclosingContainer())
|
||||||
for (auto const* decl: _container.enclosingContainer()->resolveName(_declaration.name(), true))
|
for (auto const* decl: _container.enclosingContainer()->resolveName(name, true))
|
||||||
shadowedDeclaration = decl;
|
shadowedDeclaration = decl;
|
||||||
|
|
||||||
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract()))
|
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract()))
|
||||||
|
@ -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()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user