From acbdcc3711d7ca5e11c6a85fc4b71be54ac859a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 14 Jun 2022 10:17:23 +0200 Subject: [PATCH] Revert the change that made events accessible in other contacts via qualified access --- Changelog.md | 1 - libsolidity/ast/AST.h | 2 +- .../semanticTests/events/event_selector.sol | 18 ++++++------------ .../semanticTests/events/simple.sol | 2 +- .../event_selector_access_foreign_contract.sol | 11 +++++++++++ .../events/event_selector_access_interface.sol | 11 +++++++++++ .../events/event_selector_access_library.sol | 10 ++++++++++ .../events/event_selector_syntax.sol | 14 ++++---------- 8 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 test/libsolidity/syntaxTests/events/event_selector_access_foreign_contract.sol create mode 100644 test/libsolidity/syntaxTests/events/event_selector_access_interface.sol create mode 100644 test/libsolidity/syntaxTests/events/event_selector_access_library.sol diff --git a/Changelog.md b/Changelog.md index 2a3f34bbd..ba091f266 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,7 +6,6 @@ Important Bugfixes: Language Features: * Add `E.selector` for a non-anonymous event `E` to access the 32-byte selector topic. - * Errors and Events allow qualified access from other contracts. Compiler Features: diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 7c6101bdd..4eba73c5d 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -1216,7 +1216,7 @@ public: FunctionTypePointer functionType(bool /*_internal*/) const override; bool isVisibleInDerivedContracts() const override { return true; } - bool isVisibleViaContractTypeAccess() const override { return true; } + bool isVisibleViaContractTypeAccess() const override { return false; /* TODO */ } EventDefinitionAnnotation& annotation() const override; diff --git a/test/libsolidity/semanticTests/events/event_selector.sol b/test/libsolidity/semanticTests/events/event_selector.sol index b6d940093..116e2329e 100644 --- a/test/libsolidity/semanticTests/events/event_selector.sol +++ b/test/libsolidity/semanticTests/events/event_selector.sol @@ -7,32 +7,26 @@ library S { library T { event E(); } -interface I { - event E(); -} contract D { event F(); } contract C is D { - function test1() external pure returns (bytes32, bytes32, bytes32) { + function test1() external pure returns (bytes32, bytes32) { assert(L.E.selector == T.E.selector); - assert(I.E.selector == L.E.selector); assert(L.E.selector != S.E.selector); assert(T.E.selector != S.E.selector); - assert(I.E.selector != S.E.selector); - return (L.E.selector, S.E.selector, I.E.selector); + return (L.E.selector, S.E.selector); } bytes32 s1 = L.E.selector; bytes32 s2 = S.E.selector; bytes32 s3 = T.E.selector; - bytes32 s4 = I.E.selector; - function test2() external returns (bytes32, bytes32, bytes32, bytes32) { - return (s1, s2, s3, s4); + function test2() external returns (bytes32, bytes32, bytes32) { + return (s1, s2, s3); } function test3() external returns (bytes32) { @@ -42,6 +36,6 @@ contract C is D { // ==== // compileViaYul: also // ---- -// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 -// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 +// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0 +// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028 // test3() -> 0x28811f5935c16a099486acb976b3a6b4942950a1425a74e9eb3e9b7f7135e12a diff --git a/test/libsolidity/semanticTests/events/simple.sol b/test/libsolidity/semanticTests/events/simple.sol index 7190de413..018c91e70 100644 --- a/test/libsolidity/semanticTests/events/simple.sol +++ b/test/libsolidity/semanticTests/events/simple.sol @@ -2,7 +2,7 @@ contract C { event E(); } -contract Test { +contract Test is C { event E(uint256, uint256); function f() public { emit C.E(); diff --git a/test/libsolidity/syntaxTests/events/event_selector_access_foreign_contract.sol b/test/libsolidity/syntaxTests/events/event_selector_access_foreign_contract.sol new file mode 100644 index 000000000..b878543fc --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_selector_access_foreign_contract.sol @@ -0,0 +1,11 @@ +contract D { + event E(); +} + +contract C { + function f() external pure returns (bytes32) { + return D.E.selector; + } +} +// ---- +// TypeError 9582: (110-113): Member "E" not found or not visible after argument-dependent lookup in type(contract D). diff --git a/test/libsolidity/syntaxTests/events/event_selector_access_interface.sol b/test/libsolidity/syntaxTests/events/event_selector_access_interface.sol new file mode 100644 index 000000000..2877fee56 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_selector_access_interface.sol @@ -0,0 +1,11 @@ +interface I { + event E(); +} + +contract C { + function f() external pure returns (bytes32) { + return I.E.selector; + } +} +// ---- +// TypeError 9582: (111-114): Member "E" not found or not visible after argument-dependent lookup in type(contract I). diff --git a/test/libsolidity/syntaxTests/events/event_selector_access_library.sol b/test/libsolidity/syntaxTests/events/event_selector_access_library.sol new file mode 100644 index 000000000..2bf248459 --- /dev/null +++ b/test/libsolidity/syntaxTests/events/event_selector_access_library.sol @@ -0,0 +1,10 @@ +library L { + event E(); +} + +contract C { + function f() external pure returns (bytes32) { + return L.E.selector; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/events/event_selector_syntax.sol b/test/libsolidity/syntaxTests/events/event_selector_syntax.sol index 14d2c94d8..ebb88d298 100644 --- a/test/libsolidity/syntaxTests/events/event_selector_syntax.sol +++ b/test/libsolidity/syntaxTests/events/event_selector_syntax.sol @@ -7,33 +7,27 @@ library S { library T { event E(); } -interface I { - event E(); -} contract D { event F(); } contract C is D { - function test1() external pure returns (bytes32, bytes32, bytes32) { + function test1() external pure returns (bytes32, bytes32) { assert(L.E.selector == T.E.selector); - assert(I.E.selector == L.E.selector); assert(L.E.selector != S.E.selector); assert(T.E.selector != S.E.selector); - assert(I.E.selector != S.E.selector); - return (L.E.selector, S.E.selector, I.E.selector); + return (L.E.selector, S.E.selector); } bytes32 s1 = L.E.selector; bytes32 s2 = S.E.selector; bytes32 s3 = T.E.selector; - bytes32 s4 = I.E.selector; - function test2() view external returns (bytes32, bytes32, bytes32, bytes32) { - return (s1, s2, s3, s4); + function test2() view external returns (bytes32, bytes32, bytes32) { + return (s1, s2, s3); } function test3() pure external returns (bytes32) {