mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add assert and tests for bound functions
This commit is contained in:
parent
a5411965e6
commit
06189ae57f
@ -529,6 +529,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
bool shortcutTaken = false;
|
bool shortcutTaken = false;
|
||||||
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
||||||
|
{
|
||||||
|
solAssert(!function.bound(), "");
|
||||||
if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration))
|
if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration))
|
||||||
{
|
{
|
||||||
// Do not directly visit the identifier, because this way, we can avoid
|
// Do not directly visit the identifier, because this way, we can avoid
|
||||||
@ -537,6 +539,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
utils().pushCombinedFunctionEntryLabel(m_context.resolveVirtualFunction(*functionDef), false);
|
utils().pushCombinedFunctionEntryLabel(m_context.resolveVirtualFunction(*functionDef), false);
|
||||||
shortcutTaken = true;
|
shortcutTaken = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!shortcutTaken)
|
if (!shortcutTaken)
|
||||||
_functionCall.expression().accept(*this);
|
_functionCall.expression().accept(*this);
|
||||||
|
@ -9388,6 +9388,25 @@ BOOST_AUTO_TEST_CASE(using_for_by_name)
|
|||||||
ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7)));
|
ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(bound_function_in_function)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
library L {
|
||||||
|
function g(function() internal returns (uint) _t) internal returns (uint) { return _t(); }
|
||||||
|
}
|
||||||
|
contract C {
|
||||||
|
using L for *;
|
||||||
|
function f() public returns (uint) {
|
||||||
|
return t.g();
|
||||||
|
}
|
||||||
|
function t() public pure returns (uint) { return 7; }
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "L");
|
||||||
|
compileAndRun(sourceCode, 0, "C", bytes(), map<string, Address>{{"L", m_contractAddress}});
|
||||||
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7)));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(bound_function_in_var)
|
BOOST_AUTO_TEST_CASE(bound_function_in_var)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
10
test/libsolidity/syntaxTests/bound/bound_all.sol
Normal file
10
test/libsolidity/syntaxTests/bound/bound_all.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
library L {
|
||||||
|
function g(function() internal returns (uint) _t) internal returns (uint) { return _t(); }
|
||||||
|
}
|
||||||
|
contract C {
|
||||||
|
using L for *;
|
||||||
|
function f() public returns (uint) {
|
||||||
|
return t.g();
|
||||||
|
}
|
||||||
|
function t() public pure returns (uint) { return 7; }
|
||||||
|
}
|
7
test/libsolidity/syntaxTests/bound/bound_call.sol
Normal file
7
test/libsolidity/syntaxTests/bound/bound_call.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
library D { function double(uint self) internal pure returns (uint) { return 2*self; } }
|
||||||
|
contract C {
|
||||||
|
using D for uint;
|
||||||
|
function f(uint a) public pure {
|
||||||
|
a.double();
|
||||||
|
}
|
||||||
|
}
|
7
test/libsolidity/syntaxTests/bound/bound_no_call.sol
Normal file
7
test/libsolidity/syntaxTests/bound/bound_no_call.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
library D { function double(uint self) public pure returns (uint) { return 2*self; } }
|
||||||
|
contract C {
|
||||||
|
using D for uint;
|
||||||
|
function f(uint a) public pure {
|
||||||
|
a.double;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user