Skip to content

Commit ce5c597

Browse files
authored
Merge pull request #11015 from ethereum/fixSelectorForInternal
[Sol->Yul] Provide selector for some internal functions.
2 parents ad48b71 + 5e94fce commit ce5c597

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,9 +1689,15 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
16891689
functionType.kind() == FunctionType::Kind::DelegateCall
16901690
)
16911691
define(IRVariable{_memberAccess}, IRVariable(_memberAccess.expression()).part("functionSelector"));
1692-
else if (functionType.kind() == FunctionType::Kind::Declaration)
1692+
else if (
1693+
functionType.kind() == FunctionType::Kind::Declaration ||
1694+
// In some situations, internal function types also provide the "selector" member.
1695+
// See Types.cpp for details.
1696+
functionType.kind() == FunctionType::Kind::Internal
1697+
)
16931698
{
16941699
solAssert(functionType.hasDeclaration(), "");
1700+
solAssert(functionType.declaration().isPartOfExternalInterface(), "");
16951701
define(IRVariable{_memberAccess}) << formatNumber(functionType.externalIdentifier() << 224) << "\n";
16961702
}
16971703
else
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract B {
2+
function g() public {}
3+
}
4+
contract C is B {
5+
bytes4 constant s2 = B.g.selector;
6+
function f() external pure returns (bytes4) { return s2; }
7+
}
8+
// ====
9+
// compileViaYul: also
10+
// ----
11+
// f() -> 0xe2179b8e00000000000000000000000000000000000000000000000000000000
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contract B {
2+
function ext() external {}
3+
function pub() public {}
4+
}
5+
6+
contract C is B {
7+
function test() public returns (bytes4, bytes4, bytes4, bytes4) {
8+
return (B.ext.selector, B.pub.selector, this.ext.selector, pub.selector);
9+
}
10+
}
11+
// ====
12+
// compileViaYul: true
13+
// ----
14+
// test() -> 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000, 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contract B {
2+
function ext() external {}
3+
function pub() public {}
4+
}
5+
6+
contract D {
7+
function test() public returns (bytes4, bytes4) {
8+
return (B.ext.selector, B.pub.selector);
9+
}
10+
}
11+
// ====
12+
// compileViaYul: true
13+
// ----
14+
// test() -> 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
contract B {
2+
function ext() external {}
3+
function pub() public {}
4+
}
5+
6+
contract C is B {
7+
function test() public pure {
8+
B.ext.selector;
9+
B.pub.selector;
10+
this.ext.selector;
11+
pub.selector;
12+
}
13+
}
14+
15+
contract D {
16+
function test() public pure {
17+
B.ext.selector;
18+
B.pub.selector;
19+
}
20+
}
21+
// ----
22+
// Warning 6133: (136-150): Statement has no effect.
23+
// Warning 6133: (160-174): Statement has no effect.
24+
// Warning 6133: (184-201): Statement has no effect.
25+
// Warning 6133: (289-303): Statement has no effect.
26+
// Warning 6133: (313-327): Statement has no effect.

0 commit comments

Comments
 (0)