From b0a986ffff0f077181e927d2e9f129c304b62828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 7 Sep 2023 16:13:10 +0200 Subject: [PATCH] Allow event definitions at file level --- Changelog.md | 1 + docs/contracts/events.rst | 5 +- docs/grammar/SolidityParser.g4 | 1 + docs/structure-of-a-contract.rst | 6 +- libsolidity/parsing/Parser.cpp | 3 + test/libsolidity/ABIJson/event_file_level.sol | 107 ++++++++++++++++++ test/libsolidity/SemanticTest.cpp | 2 +- .../natspecJSON/emit_file_level_event.sol | 39 +++++++ .../emit_file_level_event_inheritance.sol | 69 +++++++++++ ...t_with_same_signature_as_foreign_event.sol | 60 ++++++++++ .../natspecJSON/unused_file_level_event.sol | 21 ++++ .../events/event_emit_file_level.sol | 10 ++ .../events/event_selector_file_level.sol | 15 +++ .../events/event_shadowing_file_level.sol | 38 +++++++ .../events_with_same_name_file_level.sol | 32 ++++++ .../event_emit_qualified_file_level.sol | 8 ++ .../events/event_emit_simple_file_level.sol | 7 ++ .../event_selector_access_file_level.sol | 7 ++ .../syntaxTests/events/file_level_event.sol | 11 ++ .../file_level_event_duplicate_definition.sol | 4 + ..._event_duplicate_definition_via_import.sol | 8 ++ .../events/file_level_event_import.sol | 12 ++ .../events/file_level_event_overloading.sol | 11 ++ ...e_level_event_overloading_vs_shadowing.sol | 13 +++ ...e_level_event_shadowed_inside_contract.sol | 17 +++ ...hadowed_inside_contract_adds_anonymous.sol | 17 +++ .../file_level_event_shadowing_contract.sol | 4 + .../file_level_event_shadowing_error.sol | 4 + .../events/file_level_event_using.sol | 6 + .../illegal_names_exception_file_level.sol | 4 + 30 files changed, 536 insertions(+), 6 deletions(-) create mode 100644 test/libsolidity/ABIJson/event_file_level.sol create mode 100644 test/libsolidity/natspecJSON/emit_file_level_event.sol create mode 100644 test/libsolidity/natspecJSON/emit_file_level_event_inheritance.sol create mode 100644 test/libsolidity/natspecJSON/emit_file_level_event_with_same_signature_as_foreign_event.sol create mode 100644 test/libsolidity/natspecJSON/unused_file_level_event.sol create mode 100644 test/libsolidity/semanticTests/events/event_emit_file_level.sol create mode 100644 test/libsolidity/semanticTests/events/event_selector_file_level.sol create mode 100644 test/libsolidity/semanticTests/events/event_shadowing_file_level.sol create mode 100644 test/libsolidity/semanticTests/events/events_with_same_name_file_level.sol create mode 100644 test/libsolidity/syntaxTests/events/event_emit_qualified_file_level.sol create mode 100644 test/libsolidity/syntaxTests/events/event_emit_simple_file_level.sol create mode 100644 test/libsolidity/syntaxTests/events/event_selector_access_file_level.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition_via_import.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_import.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_overloading.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_overloading_vs_shadowing.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract_adds_anonymous.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_shadowing_contract.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_shadowing_error.sol create mode 100644 test/libsolidity/syntaxTests/events/file_level_event_using.sol create mode 100644 test/libsolidity/syntaxTests/events/illegal_names_exception_file_level.sol diff --git a/Changelog.md b/Changelog.md index cdabe189b..5fdd6b78e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.8.22 (unreleased) Language Features: + * Allow defining events at file level. Compiler Features: diff --git a/docs/contracts/events.rst b/docs/contracts/events.rst index ca992e6ca..84b5293c0 100644 --- a/docs/contracts/events.rst +++ b/docs/contracts/events.rst @@ -9,9 +9,10 @@ Events Solidity events give an abstraction on top of the EVM's logging functionality. Applications can subscribe and listen to these events through the RPC interface of an Ethereum client. -Events are inheritable members of contracts. When you call them, they cause the +Events can be defined at file level or as inheritable members of contracts (including interfaces and libraries). +When you call them, they cause the arguments to be stored in the transaction's log - a special data structure -in the blockchain. These logs are associated with the address of the contract, +in the blockchain. These logs are associated with the address of the contract that emitted them, are incorporated into the blockchain, and stay there as long as a block is accessible (forever as of now, but this might change with Serenity). The Log and its event data is not accessible from within diff --git a/docs/grammar/SolidityParser.g4 b/docs/grammar/SolidityParser.g4 index b8744673d..4a756029c 100644 --- a/docs/grammar/SolidityParser.g4 +++ b/docs/grammar/SolidityParser.g4 @@ -22,6 +22,7 @@ sourceUnit: ( | enumDefinition | userDefinedValueTypeDefinition | errorDefinition + | eventDefinition )* EOF; //@doc: inline diff --git a/docs/structure-of-a-contract.rst b/docs/structure-of-a-contract.rst index 740cce861..51d99a803 100644 --- a/docs/structure-of-a-contract.rst +++ b/docs/structure-of-a-contract.rst @@ -112,11 +112,11 @@ Events are convenience interfaces with the EVM logging facilities. .. code-block:: solidity // SPDX-License-Identifier: GPL-3.0 - pragma solidity >=0.4.21 <0.9.0; + pragma solidity ^0.8.22; + + event HighestBidIncreased(address bidder, uint amount); // Event contract SimpleAuction { - event HighestBidIncreased(address bidder, uint amount); // Event - function bid() public payable { // ... emit HighestBidIncreased(msg.sender, msg.value); // Triggering event diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 1f5611a2f..76b5d23d3 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -131,6 +131,9 @@ ASTPointer Parser::parse(CharStream& _charStream) case Token::Function: nodes.push_back(parseFunctionDefinition(true)); break; + case Token::Event: + nodes.push_back(parseEventDefinition()); + break; default: if ( // Workaround because `error` is not a keyword. diff --git a/test/libsolidity/ABIJson/event_file_level.sol b/test/libsolidity/ABIJson/event_file_level.sol new file mode 100644 index 000000000..5b5c39a82 --- /dev/null +++ b/test/libsolidity/ABIJson/event_file_level.sol @@ -0,0 +1,107 @@ +event Event(); +event Event(uint); + +event UnusedEvent(); + +function f() { + emit Event(); +} + +contract C { + function c_main() public { + emit Event(42); + f(); + } +} + +contract D is C { + event Event(string); + + function d_main() public { + emit Event("abc"); + } +} +// ---- +// :C +// [ +// { +// "anonymous": false, +// "inputs": [], +// "name": "Event", +// "type": "event" +// }, +// { +// "anonymous": false, +// "inputs": +// [ +// { +// "indexed": false, +// "internalType": "uint256", +// "name": "", +// "type": "uint256" +// } +// ], +// "name": "Event", +// "type": "event" +// }, +// { +// "inputs": [], +// "name": "c_main", +// "outputs": [], +// "stateMutability": "nonpayable", +// "type": "function" +// } +// ] +// +// +// :D +// [ +// { +// "anonymous": false, +// "inputs": [], +// "name": "Event", +// "type": "event" +// }, +// { +// "anonymous": false, +// "inputs": +// [ +// { +// "indexed": false, +// "internalType": "uint256", +// "name": "", +// "type": "uint256" +// } +// ], +// "name": "Event", +// "type": "event" +// }, +// { +// "anonymous": false, +// "inputs": +// [ +// { +// "indexed": false, +// "internalType": "string", +// "name": "", +// "type": "string" +// } +// ], +// "name": "Event", +// "type": "event" +// }, +// { +// "inputs": [], +// "name": "c_main", +// "outputs": [], +// "stateMutability": "nonpayable", +// "type": "function" +// }, +// { +// "inputs": [], +// "name": "d_main", +// "outputs": [], +// "stateMutability": "nonpayable", +// "type": "function" +// } +// ] diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index e576ae69d..f59c61ad8 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -274,7 +274,7 @@ std::optional SemanticTest::matchEvent(util::h256 const for (std::string& contractName: m_compiler.contractNames()) { ContractDefinition const& contract = m_compiler.contractDefinition(contractName); - for (EventDefinition const* event: contract.events()) + for (EventDefinition const* event: contract.events() + contract.usedInterfaceEvents()) { FunctionTypePointer eventFunctionType = event->functionType(true); if (!event->isAnonymous() && keccak256(eventFunctionType->externalSignature()) == hash) diff --git a/test/libsolidity/natspecJSON/emit_file_level_event.sol b/test/libsolidity/natspecJSON/emit_file_level_event.sol new file mode 100644 index 000000000..42c028ec9 --- /dev/null +++ b/test/libsolidity/natspecJSON/emit_file_level_event.sol @@ -0,0 +1,39 @@ +/// @notice Userdoc for file-level event E. +/// @dev Devdoc for file-level E. +event E(); + +contract C { + function f() public { + emit E(); + } +} + +// ---- +// ---- +// :C devdoc +// { +// "events": +// { +// "E()": +// { +// "details": "Devdoc for file-level E." +// } +// }, +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :C userdoc +// { +// "events": +// { +// "E()": +// { +// "notice": "Userdoc for file-level event E." +// } +// }, +// "kind": "user", +// "methods": {}, +// "version": 1 +// } diff --git a/test/libsolidity/natspecJSON/emit_file_level_event_inheritance.sol b/test/libsolidity/natspecJSON/emit_file_level_event_inheritance.sol new file mode 100644 index 000000000..f8660a274 --- /dev/null +++ b/test/libsolidity/natspecJSON/emit_file_level_event_inheritance.sol @@ -0,0 +1,69 @@ +/// @notice Userdoc for file-level event E. +/// @dev Devdoc for file-level E. +event E(); + +contract C { + function f() public { + emit E(); + } +} + +contract D is C {} + +// ---- +// ---- +// :C devdoc +// { +// "events": +// { +// "E()": +// { +// "details": "Devdoc for file-level E." +// } +// }, +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :C userdoc +// { +// "events": +// { +// "E()": +// { +// "notice": "Userdoc for file-level event E." +// } +// }, +// "kind": "user", +// "methods": {}, +// "version": 1 +// } +// +// :D devdoc +// { +// "events": +// { +// "E()": +// { +// "details": "Devdoc for file-level E." +// } +// }, +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :D userdoc +// { +// "events": +// { +// "E()": +// { +// "notice": "Userdoc for file-level event E." +// } +// }, +// "kind": "user", +// "methods": {}, +// "version": 1 +// } diff --git a/test/libsolidity/natspecJSON/emit_file_level_event_with_same_signature_as_foreign_event.sol b/test/libsolidity/natspecJSON/emit_file_level_event_with_same_signature_as_foreign_event.sol new file mode 100644 index 000000000..0e0844349 --- /dev/null +++ b/test/libsolidity/natspecJSON/emit_file_level_event_with_same_signature_as_foreign_event.sol @@ -0,0 +1,60 @@ +/// @notice Userdoc for file-level event E. +/// @dev Devdoc for file-level E. +event E(); + +contract F { + /// @notice Userdoc for event F.E. + /// @dev Devdoc for event F.E. + event E(); +} + +contract C { + function f() public { + emit E(); + emit F.E(); + } +} + +// ---- +// ---- +// :C devdoc +// { +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :C userdoc +// { +// "kind": "user", +// "methods": {}, +// "version": 1 +// } +// +// :F devdoc +// { +// "events": +// { +// "E()": +// { +// "details": "Devdoc for event F.E." +// } +// }, +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :F userdoc +// { +// "events": +// { +// "E()": +// { +// "notice": "Userdoc for event F.E." +// } +// }, +// "kind": "user", +// "methods": {}, +// "version": 1 +// } diff --git a/test/libsolidity/natspecJSON/unused_file_level_event.sol b/test/libsolidity/natspecJSON/unused_file_level_event.sol new file mode 100644 index 000000000..4a621f383 --- /dev/null +++ b/test/libsolidity/natspecJSON/unused_file_level_event.sol @@ -0,0 +1,21 @@ +/// @notice Userdoc for file-level event E. +/// @dev Devdoc for file-level E. +event E(); + +contract C {} + +// ---- +// ---- +// :C devdoc +// { +// "kind": "dev", +// "methods": {}, +// "version": 1 +// } +// +// :C userdoc +// { +// "kind": "user", +// "methods": {}, +// "version": 1 +// } diff --git a/test/libsolidity/semanticTests/events/event_emit_file_level.sol b/test/libsolidity/semanticTests/events/event_emit_file_level.sol new file mode 100644 index 000000000..b698bb80b --- /dev/null +++ b/test/libsolidity/semanticTests/events/event_emit_file_level.sol @@ -0,0 +1,10 @@ +event Deposit(address indexed _from, bytes32 indexed _id, uint _value); + +contract ClientReceipt { + function deposit(bytes32 _id) public payable { + emit Deposit(msg.sender, _id, msg.value); + } +} +// ---- +// deposit(bytes32), 18 wei: 0x1234 -> +// ~ emit Deposit(address,bytes32,uint256): #0x1212121212121212121212121212120000000012, #0x1234, 0x12 diff --git a/test/libsolidity/semanticTests/events/event_selector_file_level.sol b/test/libsolidity/semanticTests/events/event_selector_file_level.sol new file mode 100644 index 000000000..8c5b6c95b --- /dev/null +++ b/test/libsolidity/semanticTests/events/event_selector_file_level.sol @@ -0,0 +1,15 @@ +event E(); + +library L { + event E(); +} + +contract C { + function main() external pure returns (bytes32, bytes32) { + assert(E.selector == L.E.selector); + + return (E.selector, L.E.selector); + } +} +// ---- +// main() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 diff --git a/test/libsolidity/semanticTests/events/event_shadowing_file_level.sol b/test/libsolidity/semanticTests/events/event_shadowing_file_level.sol new file mode 100644 index 000000000..01c7d85ae --- /dev/null +++ b/test/libsolidity/semanticTests/events/event_shadowing_file_level.sol @@ -0,0 +1,38 @@ +event E(); + +library L1 { + event E(string); +} + +library L2 { + event E(); +} + +library K { + function main() internal pure returns (bytes32, bytes32, bytes32) { + // Here E is the global event. + assert(E.selector != L1.E.selector); + assert(E.selector == L2.E.selector); + + return (E.selector, L1.E.selector, L2.E.selector); + } +} + +contract C { + event E(string); + + function main() external pure returns (bytes32, bytes32, bytes32) { + // Here E is the local event. + assert(E.selector == L1.E.selector); + assert(E.selector != L2.E.selector); + + return (E.selector, L1.E.selector, L2.E.selector); + } + + function k_main() external pure returns (bytes32, bytes32, bytes32) { + return K.main(); + } +} +// ---- +// main() -> 0x3e9992c940c54ea252d3a34557cc3d3014281525c43d694f89d5f3dfd820b07d, 0x3e9992c940c54ea252d3a34557cc3d3014281525c43d694f89d5f3dfd820b07d, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 +// k_main() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x3e9992c940c54ea252d3a34557cc3d3014281525c43d694f89d5f3dfd820b07d, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 diff --git a/test/libsolidity/semanticTests/events/events_with_same_name_file_level.sol b/test/libsolidity/semanticTests/events/events_with_same_name_file_level.sol new file mode 100644 index 000000000..222e0b0ce --- /dev/null +++ b/test/libsolidity/semanticTests/events/events_with_same_name_file_level.sol @@ -0,0 +1,32 @@ +event Deposit(); +event Deposit(address _addr); +event Deposit(address _addr, uint _amount); +event Deposit(address _addr, bool _flag); + +contract ClientReceipt { + function deposit() public returns (uint) { + emit Deposit(); + return 1; + } + function deposit(address _addr) public returns (uint) { + emit Deposit(_addr); + return 2; + } + function deposit(address _addr, uint _amount) public returns (uint) { + emit Deposit(_addr, _amount); + return 3; + } + function deposit(address _addr, bool _flag) public returns (uint) { + emit Deposit(_addr, _flag); + return 4; + } +} +// ---- +// deposit() -> 1 +// ~ emit Deposit() +// deposit(address): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988 -> 2 +// ~ emit Deposit(address): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988 +// deposit(address,uint256): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988, 100 -> 3 +// ~ emit Deposit(address,uint256): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988, 0x64 +// deposit(address,bool): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988, false -> 4 +// ~ emit Deposit(address,bool): 0x5082a85c489be6aa0f2e6693bf09cc1bbd35e988, false diff --git a/test/libsolidity/syntaxTests/events/event_emit_qualified_file_level.sol b/test/libsolidity/syntaxTests/events/event_emit_qualified_file_level.sol new file mode 100644 index 000000000..6d1cc65de --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_emit_qualified_file_level.sol @@ -0,0 +1,8 @@ +==== Source: M.sol ==== +event E(); +==== Source: A.sol ==== +import "M.sol" as M; + +function f() { + emit M.E(); +} diff --git a/test/libsolidity/syntaxTests/events/event_emit_simple_file_level.sol b/test/libsolidity/syntaxTests/events/event_emit_simple_file_level.sol new file mode 100644 index 000000000..46fda33bc --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_emit_simple_file_level.sol @@ -0,0 +1,7 @@ +event E(); + +contract C { + function f() public { + emit E(); + } +} diff --git a/test/libsolidity/syntaxTests/events/event_selector_access_file_level.sol b/test/libsolidity/syntaxTests/events/event_selector_access_file_level.sol new file mode 100644 index 000000000..1131e00b6 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_selector_access_file_level.sol @@ -0,0 +1,7 @@ +event E(); + +contract C { + function f() external pure returns (bytes32) { + return E.selector; + } +} diff --git a/test/libsolidity/syntaxTests/events/file_level_event.sol b/test/libsolidity/syntaxTests/events/file_level_event.sol new file mode 100644 index 000000000..33d4378fd --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event.sol @@ -0,0 +1,11 @@ +event E1(); +event E2(uint); +event E3(uint, string indexed, bytes, bool); +event E4(int, int, int) anonymous; + +function f() { + emit E1(); + emit E2(1); + emit E3(1, "abc", "abc", true); + emit E4(1, 2, 3); +} diff --git a/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition.sol b/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition.sol new file mode 100644 index 000000000..30d3594ea --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition.sol @@ -0,0 +1,4 @@ +event E(); +event E(); +// ---- +// DeclarationError 5883: (0-10): Event with same name and parameter types defined twice. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition_via_import.sol b/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition_via_import.sol new file mode 100644 index 000000000..0cd9c8c2a --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_duplicate_definition_via_import.sol @@ -0,0 +1,8 @@ +==== Source: A.sol ==== +event E(); +==== Source: B.sol ==== +import "A.sol"; + +event E(); +// ---- +// DeclarationError 5883: (B.sol:17-27): Event with same name and parameter types defined twice. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_import.sol b/test/libsolidity/syntaxTests/events/file_level_event_import.sol new file mode 100644 index 000000000..c2591a18f --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_import.sol @@ -0,0 +1,12 @@ +==== Source: A.sol ==== +event EA(); +==== Source: B.sol ==== +event EB(); +==== Source: C.sol ==== +import "A.sol"; +import {EB} from "B.sol"; + +function f() { + emit EA(); + emit EB(); +} diff --git a/test/libsolidity/syntaxTests/events/file_level_event_overloading.sol b/test/libsolidity/syntaxTests/events/file_level_event_overloading.sol new file mode 100644 index 000000000..1f4ac3382 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_overloading.sol @@ -0,0 +1,11 @@ +event E(); +event E(uint); +event E(uint, string indexed, bytes, bool); +event E(int, int, int) anonymous; + +function f() { + emit E(); + emit E(1); + emit E(1, "abc", "abc", true); + emit E(1, 2, 3); +} diff --git a/test/libsolidity/syntaxTests/events/file_level_event_overloading_vs_shadowing.sol b/test/libsolidity/syntaxTests/events/file_level_event_overloading_vs_shadowing.sol new file mode 100644 index 000000000..f6268b286 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_overloading_vs_shadowing.sol @@ -0,0 +1,13 @@ +event E(); + +contract C { + event E(uint); + + function f() public { + emit E(); + emit E(1); + } +} +// ---- +// Warning 2519: (29-43): This declaration shadows an existing declaration. +// TypeError 6160: (84-87): Wrong argument count for function call: 0 arguments given but expected 1. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract.sol b/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract.sol new file mode 100644 index 000000000..1408e5434 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract.sol @@ -0,0 +1,17 @@ +event E(); + +contract C { + event E(); +} + +library L { + event E(); +} + +interface I { + event E(); +} +// ---- +// Warning 2519: (29-39): This declaration shadows an existing declaration. +// Warning 2519: (59-69): This declaration shadows an existing declaration. +// Warning 2519: (91-101): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract_adds_anonymous.sol b/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract_adds_anonymous.sol new file mode 100644 index 000000000..1b95ac7d1 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_shadowed_inside_contract_adds_anonymous.sol @@ -0,0 +1,17 @@ +event E(); + +contract C { + event E() anonymous; +} + +library L { + event E() anonymous; +} + +interface I { + event E() anonymous; +} +// ---- +// Warning 2519: (29-49): This declaration shadows an existing declaration. +// Warning 2519: (69-89): This declaration shadows an existing declaration. +// Warning 2519: (111-131): This declaration shadows an existing declaration. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_shadowing_contract.sol b/test/libsolidity/syntaxTests/events/file_level_event_shadowing_contract.sol new file mode 100644 index 000000000..1ebe600e5 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_shadowing_contract.sol @@ -0,0 +1,4 @@ +event E(); +contract E {} +// ---- +// DeclarationError 2333: (11-24): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_shadowing_error.sol b/test/libsolidity/syntaxTests/events/file_level_event_shadowing_error.sol new file mode 100644 index 000000000..c6ba8e9c7 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_shadowing_error.sol @@ -0,0 +1,4 @@ +event E(); +error E(); +// ---- +// DeclarationError 2333: (11-21): Identifier already declared. diff --git a/test/libsolidity/syntaxTests/events/file_level_event_using.sol b/test/libsolidity/syntaxTests/events/file_level_event_using.sol new file mode 100644 index 000000000..99827d0b8 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/file_level_event_using.sol @@ -0,0 +1,6 @@ +event E(); + +type T is uint; +using {E} for T; +// ---- +// TypeError 8187: (35-36): Expected function name. diff --git a/test/libsolidity/syntaxTests/events/illegal_names_exception_file_level.sol b/test/libsolidity/syntaxTests/events/illegal_names_exception_file_level.sol new file mode 100644 index 000000000..48b23dc38 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/illegal_names_exception_file_level.sol @@ -0,0 +1,4 @@ +// Exception for the illegal name list. External interface events +event this(); +event super(); +event _();