Skip to content

Commit

Permalink
Allow qualified access to events from other contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed May 26, 2023
1 parent 8c7404f commit bb6aad2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### 0.8.21 (unreleased)

Language Features:

* Allow qualified access to events from other contracts.

Compiler Features:
* EWasm: Remove EWasm backend.
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ class EventDefinition: public CallableDeclaration, public StructurallyDocumented
FunctionTypePointer functionType(bool /*_internal*/) const override;

bool isVisibleInDerivedContracts() const override { return true; }
bool isVisibleViaContractTypeAccess() const override { return false; /* TODO */ }
bool isVisibleViaContractTypeAccess() const override { return true; }

EventDefinitionAnnotation& annotation() const override;

Expand Down
22 changes: 16 additions & 6 deletions test/libsolidity/semanticTests/events/event_selector.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
library L {
event E();
}

library S {
event E(uint);
}

library T {
event E();
}

interface I {
event E();
}

contract D {
event F();
}

contract C is D {
function test1() external pure returns (bytes32, bytes32) {
function test1() external pure returns (bytes32, bytes32, bytes32) {
assert(L.E.selector == T.E.selector);
assert(I.E.selector == L.E.selector);
assert(T.E.selector == I.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);
return (L.E.selector, S.E.selector, I.E.selector);
}

bytes32 s1 = L.E.selector;
bytes32 s2 = S.E.selector;
bytes32 s3 = T.E.selector;
function test2() external returns (bytes32, bytes32, bytes32) {
return (s1, s2, s3);
bytes32 s4 = I.E.selector;
function test2() external returns (bytes32, bytes32, bytes32, bytes32) {
return (s1, s2, s3, s4);
}

function test3() external returns (bytes32) {
Expand All @@ -36,6 +46,6 @@ contract C is D {
// ====
// compileViaYul: also
// ----
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test3() -> 0x28811f5935c16a099486acb976b3a6b4942950a1425a74e9eb3e9b7f7135e12a
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ contract C {
}
}
// ----
// TypeError 9582: (110-113): Member "E" not found or not visible after argument-dependent lookup in type(contract D).
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ contract C {
}
}
// ----
// TypeError 9582: (111-114): Member "E" not found or not visible after argument-dependent lookup in type(contract I).
15 changes: 15 additions & 0 deletions test/libsolidity/syntaxTests/events/event_selector_syntax.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@ library L {
event E(bytes32, bool, bytes indexed);
}

interface I {
event E(bytes32, bool, bytes indexed);
}

contract A {
event E(bytes32, bool, bytes indexed);
}

contract B {
event E(bytes32, bool, bytes indexed);
}

contract C is B {
bytes32 public librarySelector = L.E.selector;
bytes32 public interfaceSelector = I.E.selector;
bytes32 public foreignContractSelector = A.E.selector;
bytes32 inheritedSelector = E.selector;

function f() public {
assert(librarySelector == L.E.selector);
assert(interfaceSelector == I.E.selector);
assert(foreignContractSelector == A.E.selector);
assert(E.selector == B.E.selector);

emit E(E.selector, true, "123");
emit I.E((B.E.selector), true, "123");
emit A.E((B.E.selector), true, "123");
emit L.E((B.E.selector), true, "123");
}
}
// ----

0 comments on commit bb6aad2

Please sign in to comment.