Skip to content

Commit

Permalink
Disallow multiple events with same name and types.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth authored and hrkrshnn committed Jul 7, 2020
1 parent 312403f commit 6f052bb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Breaking changes:
* Type Checker: Exponentiation and shifts of literals by non-literals will always use ``uint256`` or ``int256`` as a type.
* Type Checker: Disallow structs and arrays in memory or calldata if they contain nested mappings.
* Type Checker: Disallow assignments to state variables that contain nested mappings.
* Type checker: Disallow events with same name and parameter types in inheritance hierarchy.

Language Features:
* Yul: Disallow EVM instruction `pc()`.
Expand Down
5 changes: 3 additions & 2 deletions libsolidity/analysis/ContractLevelChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contr
/// Checks that two events with the same name defined in this contract have different
/// argument types
map<string, vector<EventDefinition const*>> events;
for (EventDefinition const* event: _contract.events())
events[event->name()].push_back(event);
for (auto const* contract: _contract.annotation().linearizedBaseContracts)
for (EventDefinition const* event: contract->events())
events[event->name()].push_back(event);

findDuplicateDefinitions(events);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A {
event X();
}
contract B is A {
event X() anonymous;
}
// ----
// DeclarationError 5883: (52-72): Event with same name and arguments defined twice.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A {
event X(uint);
}
contract B is A {
event X(uint indexed);
}
// ----
// DeclarationError 5883: (56-78): Event with same name and arguments defined twice.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
contract A {
event X();
}
contract B is A {
event X(uint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A {
event X(uint);
}
contract B is A {
event X(uint);
}
// ----
// DeclarationError 5883: (56-70): Event with same name and arguments defined twice.
10 changes: 10 additions & 0 deletions test/libsolidity/syntaxTests/events/inheritance_multi_parent.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contract A {
event X(uint, uint indexed);
}
contract B {
event X(uint, uint);
}
contract C is A, B {
}
// ----
// DeclarationError 5883: (65-85): Event with same name and arguments defined twice.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A {
event X(uint, uint indexed);
}
contract B is A {
event X(uint, uint);
}
// ----
// DeclarationError 5883: (70-90): Event with same name and arguments defined twice.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract A {
event X();
event X(uint);
}
// ----

0 comments on commit 6f052bb

Please sign in to comment.