Allow qualified access to events from other contracts

This commit is contained in:
Nikola Matic 2023-05-26 11:08:34 +02:00
parent 8c7404f639
commit 5893e099fe
6 changed files with 40 additions and 10 deletions

View File

@ -1,7 +1,7 @@
### 0.8.21 (unreleased)
Language Features:
* Allow qualified access to events from other contracts.
Compiler Features:
* EWasm: Remove EWasm backend.

View File

@ -1261,7 +1261,7 @@ public:
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;

View File

@ -1,32 +1,49 @@
library L {
event E();
}
library S {
event E(uint);
}
library T {
event E();
}
interface I {
event E();
}
contract B {
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, bytes32) {
assert(L.E.selector == T.E.selector);
assert(I.E.selector == L.E.selector);
assert(T.E.selector == I.E.selector);
assert(B.E.selector == T.E.selector);
assert(L.E.selector != S.E.selector);
assert(T.E.selector != S.E.selector);
assert(I.E.selector != S.E.selector);
assert(B.E.selector != S.E.selector);
return (L.E.selector, S.E.selector);
return (L.E.selector, S.E.selector, I.E.selector, B.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;
bytes32 s5 = B.E.selector;
function test2() external returns (bytes32, bytes32, bytes32, bytes32, bytes32) {
return (s1, s2, s3, s4, s5);
}
function test3() external returns (bytes32) {
@ -36,6 +53,6 @@ contract C is D {
// ====
// compileViaYul: also
// ----
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test1() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test2() -> 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x2ff0672f372fbe844b353429d4510ea5e43683af134c54f75f789ff57bc0c0, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028, 0x92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028
// test3() -> 0x28811f5935c16a099486acb976b3a6b4942950a1425a74e9eb3e9b7f7135e12a

View File

@ -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).

View File

@ -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).

View File

@ -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");
}
}
// ----