aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-23 01:23:46 +0800
committerGitHub <noreply@github.com>2018-11-23 01:23:46 +0800
commitecd059cb9225c5b9d01a928b1495aff31e3773ee (patch)
tree7c182755c8fdac9eff202b54f6330dc39073829f
parentb0e4ef7a1325b160e225745264317c0046c39f71 (diff)
parent06189ae57f2f556f21499938fca8f9c0db82779e (diff)
downloaddexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar.gz
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar.bz2
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar.lz
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar.xz
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.tar.zst
dexon-solidity-ecd059cb9225c5b9d01a928b1495aff31e3773ee.zip
Merge pull request #5451 from ethereum/bound_function_tests
Add assert and tests for bound functions
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp3
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp19
-rw-r--r--test/libsolidity/syntaxTests/bound/bound_all.sol10
-rw-r--r--test/libsolidity/syntaxTests/bound/bound_call.sol7
-rw-r--r--test/libsolidity/syntaxTests/bound/bound_no_call.sol7
5 files changed, 46 insertions, 0 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 57b513d2..b0d17286 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -529,6 +529,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
{
bool shortcutTaken = false;
if (auto identifier = dynamic_cast<Identifier const*>(&_functionCall.expression()))
+ {
+ solAssert(!function.bound(), "");
if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration))
{
// 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);
shortcutTaken = true;
}
+ }
if (!shortcutTaken)
_functionCall.expression().accept(*this);
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 041f29a8..e591432a 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -9388,6 +9388,25 @@ BOOST_AUTO_TEST_CASE(using_for_by_name)
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)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/syntaxTests/bound/bound_all.sol b/test/libsolidity/syntaxTests/bound/bound_all.sol
new file mode 100644
index 00000000..29f55b88
--- /dev/null
+++ b/test/libsolidity/syntaxTests/bound/bound_all.sol
@@ -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; }
+}
diff --git a/test/libsolidity/syntaxTests/bound/bound_call.sol b/test/libsolidity/syntaxTests/bound/bound_call.sol
new file mode 100644
index 00000000..281f19b4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/bound/bound_call.sol
@@ -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();
+ }
+}
diff --git a/test/libsolidity/syntaxTests/bound/bound_no_call.sol b/test/libsolidity/syntaxTests/bound/bound_no_call.sol
new file mode 100644
index 00000000..dcb3c3c5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/bound/bound_no_call.sol
@@ -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;
+ }
+}