Skip to content

Commit

Permalink
Do not consider shadowing in variable names inside event declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond committed Oct 4, 2017
1 parent 19274c7 commit 76d3d24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Bugfixes:
* Type Checker: Properly support overwriting members inherited from ``address`` in a contract
(such as ``balance``, ``transfer``, etc.)
* Type Checker: Prevent duplicate event declarations.
* Type Checker: Do not mark event parameters as shadowing state variables.

### 0.4.17 (2017-09-21)

Expand Down
6 changes: 4 additions & 2 deletions libsolidity/analysis/NameAndTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,12 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio

bool warnAboutShadowing = true;
// Do not warn about shadowing for structs and enums because their members are
// not accessible without prefixes.
// not accessible without prefixes. Also do not warn about event parameters
// because they don't participate in any proper scope.
if (
dynamic_cast<StructDefinition const*>(m_currentScope) ||
dynamic_cast<EnumDefinition const*>(m_currentScope)
dynamic_cast<EnumDefinition const*>(m_currentScope) ||
dynamic_cast<EventDefinition const*>(m_currentScope)
)
warnAboutShadowing = false;
// Do not warn about the constructor shadowing the contract.
Expand Down
11 changes: 11 additions & 0 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6371,6 +6371,17 @@ BOOST_AUTO_TEST_CASE(function_override_is_not_shadowing)
CHECK_SUCCESS_NO_WARNINGS(text);
}

BOOST_AUTO_TEST_CASE(event_parameter_cannot_shadow_state_variable)
{
char const* text = R"(
contract C {
address a;
event E(address a);
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}

BOOST_AUTO_TEST_CASE(callable_crash)
{
char const* text = R"(
Expand Down

0 comments on commit 76d3d24

Please sign in to comment.