mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11015 from ethereum/fixSelectorForInternal
[Sol->Yul] Provide selector for some internal functions.
This commit is contained in:
commit
ce5c5970d6
@ -1689,9 +1689,15 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
||||
functionType.kind() == FunctionType::Kind::DelegateCall
|
||||
)
|
||||
define(IRVariable{_memberAccess}, IRVariable(_memberAccess.expression()).part("functionSelector"));
|
||||
else if (functionType.kind() == FunctionType::Kind::Declaration)
|
||||
else if (
|
||||
functionType.kind() == FunctionType::Kind::Declaration ||
|
||||
// In some situations, internal function types also provide the "selector" member.
|
||||
// See Types.cpp for details.
|
||||
functionType.kind() == FunctionType::Kind::Internal
|
||||
)
|
||||
{
|
||||
solAssert(functionType.hasDeclaration(), "");
|
||||
solAssert(functionType.declaration().isPartOfExternalInterface(), "");
|
||||
define(IRVariable{_memberAccess}) << formatNumber(functionType.externalIdentifier() << 224) << "\n";
|
||||
}
|
||||
else
|
||||
|
@ -0,0 +1,11 @@
|
||||
contract B {
|
||||
function g() public {}
|
||||
}
|
||||
contract C is B {
|
||||
bytes4 constant s2 = B.g.selector;
|
||||
function f() external pure returns (bytes4) { return s2; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0xe2179b8e00000000000000000000000000000000000000000000000000000000
|
14
test/libsolidity/semanticTests/functionTypes/selector_1.sol
Normal file
14
test/libsolidity/semanticTests/functionTypes/selector_1.sol
Normal file
@ -0,0 +1,14 @@
|
||||
contract B {
|
||||
function ext() external {}
|
||||
function pub() public {}
|
||||
}
|
||||
|
||||
contract C is B {
|
||||
function test() public returns (bytes4, bytes4, bytes4, bytes4) {
|
||||
return (B.ext.selector, B.pub.selector, this.ext.selector, pub.selector);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// test() -> 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000, 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000
|
14
test/libsolidity/semanticTests/functionTypes/selector_2.sol
Normal file
14
test/libsolidity/semanticTests/functionTypes/selector_2.sol
Normal file
@ -0,0 +1,14 @@
|
||||
contract B {
|
||||
function ext() external {}
|
||||
function pub() public {}
|
||||
}
|
||||
|
||||
contract D {
|
||||
function test() public returns (bytes4, bytes4) {
|
||||
return (B.ext.selector, B.pub.selector);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// test() -> 0xcf9f23b500000000000000000000000000000000000000000000000000000000, 0x7defb41000000000000000000000000000000000000000000000000000000000
|
26
test/libsolidity/syntaxTests/functionTypes/selectors.sol
Normal file
26
test/libsolidity/syntaxTests/functionTypes/selectors.sol
Normal file
@ -0,0 +1,26 @@
|
||||
contract B {
|
||||
function ext() external {}
|
||||
function pub() public {}
|
||||
}
|
||||
|
||||
contract C is B {
|
||||
function test() public pure {
|
||||
B.ext.selector;
|
||||
B.pub.selector;
|
||||
this.ext.selector;
|
||||
pub.selector;
|
||||
}
|
||||
}
|
||||
|
||||
contract D {
|
||||
function test() public pure {
|
||||
B.ext.selector;
|
||||
B.pub.selector;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6133: (136-150): Statement has no effect.
|
||||
// Warning 6133: (160-174): Statement has no effect.
|
||||
// Warning 6133: (184-201): Statement has no effect.
|
||||
// Warning 6133: (289-303): Statement has no effect.
|
||||
// Warning 6133: (313-327): Statement has no effect.
|
Loading…
Reference in New Issue
Block a user