Skip to content

Commit 1349620

Browse files
committed
Allow qualified access to events from other contracts
1 parent 8c7404f commit 1349620

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### 0.8.21 (unreleased)
22

33
Language Features:
4-
4+
* Allow qualified access to events from other contracts.
55

66
Compiler Features:
77
* EWasm: Remove EWasm backend.

libsolidity/ast/AST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ class EventDefinition: public CallableDeclaration, public StructurallyDocumented
12611261
FunctionTypePointer functionType(bool /*_internal*/) const override;
12621262

12631263
bool isVisibleInDerivedContracts() const override { return true; }
1264-
bool isVisibleViaContractTypeAccess() const override { return false; /* TODO */ }
1264+
bool isVisibleViaContractTypeAccess() const override { return true; }
12651265

12661266
EventDefinitionAnnotation& annotation() const override;
12671267

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
library L {
22
event E();
33
}
4+
45
library S {
56
event E(uint);
67
}
8+
79
library T {
810
event E();
911
}
1012

13+
interface I {
14+
event E();
15+
}
16+
1117
contract D {
1218
event F();
1319
}
1420

1521
contract C is D {
16-
function test1() external pure returns (bytes32, bytes32) {
22+
function test1() external pure returns (bytes32, bytes32, bytes32) {
1723
assert(L.E.selector == T.E.selector);
24+
assert(I.E.selector == L.E.selector);
25+
assert(T.E.selector == I.E.selector);
1826

1927
assert(L.E.selector != S.E.selector);
2028
assert(T.E.selector != S.E.selector);
29+
assert(I.E.selector != S.E.selector);
2130

22-
return (L.E.selector, S.E.selector);
31+
return (L.E.selector, S.E.selector, I.E.selector);
2332
}
2433

2534
bytes32 s1 = L.E.selector;
2635
bytes32 s2 = S.E.selector;
2736
bytes32 s3 = T.E.selector;
28-
function test2() external returns (bytes32, bytes32, bytes32) {
29-
return (s1, s2, s3);
37+
bytes32 s4 = I.E.selector;
38+
function test2() external returns (bytes32, bytes32, bytes32, bytes32) {
39+
return (s1, s2, s3, s4);
3040
}
3141

3242
function test3() external returns (bytes32) {
@@ -36,6 +46,6 @@ contract C is D {
3646
// ====
3747
// compileViaYul: also
3848
// ----
39-
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0
40-
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
49+
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
50+
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
4151
// test3() -> 0x28811f5935c16a099486acb976b3a6b4942950a1425a74e9eb3e9b7f7135e12a

test/libsolidity/syntaxTests/events/event_selector_access_foreign_contract.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ contract C {
88
}
99
}
1010
// ----
11-
// TypeError 9582: (110-113): Member "E" not found or not visible after argument-dependent lookup in type(contract D).

test/libsolidity/syntaxTests/events/event_selector_access_interface.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ contract C {
88
}
99
}
1010
// ----
11-
// TypeError 9582: (111-114): Member "E" not found or not visible after argument-dependent lookup in type(contract I).

test/libsolidity/syntaxTests/events/event_selector_syntax.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ library L {
22
event E(bytes32, bool, bytes indexed);
33
}
44

5+
interface I {
6+
event E(bytes32, bool, bytes indexed);
7+
}
8+
59
contract B {
610
event E(bytes32, bool, bytes indexed);
711
}
812

913
contract C is B {
1014
bytes32 public librarySelector = L.E.selector;
15+
bytes32 public interfaceSelector = I.E.selector;
1116
bytes32 inheritedSelector = E.selector;
1217

1318
function f() public {
1419
assert(librarySelector == L.E.selector);
20+
assert(interfaceSelector == I.E.selector);
1521
assert(E.selector == B.E.selector);
1622

1723
emit E(E.selector, true, "123");
24+
emit I.E((B.E.selector), true, "123");
1825
emit L.E((B.E.selector), true, "123");
1926
}
2027
}
28+
// ----

0 commit comments

Comments
 (0)