Merge pull request #9326 from ethereum/eventOverwriting

[BREAKING] Disallow multiple events with same name and types.
This commit is contained in:
chriseth 2020-07-13 15:44:35 +02:00 committed by GitHub
commit 12f390a60a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 2 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -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.

View File

@ -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.

View File

@ -0,0 +1,6 @@
contract A {
event X();
}
contract B is A {
event X(uint);
}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -0,0 +1,4 @@
contract A { event X(uint); }
contract B is A {}
contract C is A {}
contract D is B, C {}

View File

@ -0,0 +1,5 @@
contract A {
event X();
event X(uint);
}
// ----