diff --git a/Changelog.md b/Changelog.md index 817016258631..ad06e4196abe 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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. diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index c0da545644a0..2ca95f2a5d54 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -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> 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); } diff --git a/test/libsolidity/syntaxTests/events/inheritance_adds_anonymous.sol b/test/libsolidity/syntaxTests/events/inheritance_adds_anonymous.sol new file mode 100644 index 000000000000..0e92a88b9b59 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_adds_anonymous.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/events/inheritance_adds_indexed.sol b/test/libsolidity/syntaxTests/events/inheritance_adds_indexed.sol new file mode 100644 index 000000000000..f68a96ea9601 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_adds_indexed.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/events/inheritance_adds_parameter.sol b/test/libsolidity/syntaxTests/events/inheritance_adds_parameter.sol new file mode 100644 index 000000000000..d987570c326c --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_adds_parameter.sol @@ -0,0 +1,6 @@ +contract A { + event X(); +} +contract B is A { + event X(uint); +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/events/inheritance_event_repeated.sol b/test/libsolidity/syntaxTests/events/inheritance_event_repeated.sol new file mode 100644 index 000000000000..9c19ebb33e5c --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_event_repeated.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/events/inheritance_multi_parent.sol b/test/libsolidity/syntaxTests/events/inheritance_multi_parent.sol new file mode 100644 index 000000000000..3724fc10c6c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_multi_parent.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/events/inheritance_removes_indexed.sol b/test/libsolidity/syntaxTests/events/inheritance_removes_indexed.sol new file mode 100644 index 000000000000..6379618b1840 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/inheritance_removes_indexed.sol @@ -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. diff --git a/test/libsolidity/syntaxTests/events/multiple_inheritance.sol b/test/libsolidity/syntaxTests/events/multiple_inheritance.sol new file mode 100644 index 000000000000..2cc158f7765f --- /dev/null +++ b/test/libsolidity/syntaxTests/events/multiple_inheritance.sol @@ -0,0 +1,4 @@ +contract A { event X(uint); } +contract B is A {} +contract C is A {} +contract D is B, C {} diff --git a/test/libsolidity/syntaxTests/events/overloading_in_contract.sol b/test/libsolidity/syntaxTests/events/overloading_in_contract.sol new file mode 100644 index 000000000000..9349f1751a3d --- /dev/null +++ b/test/libsolidity/syntaxTests/events/overloading_in_contract.sol @@ -0,0 +1,5 @@ +contract A { + event X(); + event X(uint); +} +// ---- \ No newline at end of file