Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Disallow multiple events with same name and types. #9326

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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.
* ``using A for B`` only affects the contract it is mentioned in and not all derived contracts
* Inline Assembly: Disallow `.` in user-defined function and variable names.

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 parameter types 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 parameter types 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 parameter types 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 parameter types 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 parameter types defined twice.
4 changes: 4 additions & 0 deletions test/libsolidity/syntaxTests/events/multiple_inheritance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract A { event X(uint); }
contract B is A {}
contract C is A {}
contract D is B, C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract A {
event X();
event X(uint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another test case with indexed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean () and (uint indexed)? There is already one with (uint, uint) and (uint, uint indexed)

}
// ----