diff --git a/Changelog.md b/Changelog.md index 49fbf8f12..d90cd3f65 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,7 @@ ### 0.4.17 (unreleased) Features: - * Code Generator: Added ``.sig`` member on external function types to retrieve their signature. + * Code Generator: Added ``.selector`` member on external function types to retrieve their signature. * Optimizer: Add new optimization step to remove unused ``JUMPDEST``s. * Type Checker: Display helpful warning for unused function arguments/return parameters. * Type Checker: Do not show the same error multiple times for events. diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 5aa52383b..705d0f7f2 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2438,7 +2438,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con MemberList::MemberMap members; if (m_kind == Kind::External) members.push_back(MemberList::Member( - "sig", + "selector", make_shared(4) )); if (m_kind != Kind::BareDelegateCall && m_kind != Kind::DelegateCall) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index b7aadc128..631a25ff9 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1068,7 +1068,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) solAssert(false, "Invalid member access to integer"); break; case Type::Category::Function: - if (member == "sig") + if (member == "selector") { m_context << Instruction::SWAP1 << Instruction::POP; /// need to store store it as bytes4 diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f3d0fde36..661d184a0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10056,16 +10056,16 @@ BOOST_AUTO_TEST_CASE(function_types_sig) char const* sourceCode = R"( contract C { function f() returns (bytes4) { - return this.f.sig; + return this.f.selector; } function g() returns (bytes4) { function () external returns (bytes4) fun = this.f; - return fun.sig; + return fun.selector; } function h() returns (bytes4) { function () external returns (bytes4) fun = this.f; var funvar = fun; - return funvar.sig; + return funvar.selector; } } )"; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 6576634fe..9f33c5b37 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6290,34 +6290,34 @@ BOOST_AUTO_TEST_CASE(function_types_sig) char const* text = R"( contract C { function f() returns (bytes4) { - return f.sig; + return f.selector; } } )"; - CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); text = R"( contract C { function g() internal { } function f() returns (bytes4) { - return g.sig; + return g.selector; } } )"; - CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); text = R"( contract C { function f() returns (bytes4) { function () g; - return g.sig; + return g.selector; } } )"; - CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); text = R"( contract C { function f() returns (bytes4) { - return this.f.sig; + return this.f.selector; } } )"; @@ -6325,7 +6325,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) text = R"( contract C { function f() external returns (bytes4) { - return this.f.sig; + return this.f.selector; } } )"; @@ -6336,7 +6336,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) } function f() external returns (bytes4) { var g = this.h; - return g.sig; + return g.selector; } } )"; @@ -6347,7 +6347,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) } function f() external returns (bytes4) { function () external g = this.h; - return g.sig; + return g.selector; } } )"; @@ -6359,7 +6359,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) function f() external returns (bytes4) { function () external g = this.h; var i = g; - return i.sig; + return i.selector; } } )";