From f574d8ec3ae1e4c499a7f15275789fee44b5c6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 26 May 2020 22:18:41 +0200 Subject: [PATCH] Don't assume that an expression cannot be associated with a function declaration --- .../codegen/ir/IRGeneratorForStatements.cpp | 2 -- .../call_internal_function_via_expression.sol | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/semanticTests/functionCall/call_internal_function_via_expression.sol diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 98c0b2169..f5591f4ae 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -675,8 +675,6 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) solAssert(functionDef->isImplemented(), ""); } - else - solAssert(!functionType->hasDeclaration(), ""); solAssert(!functionType->takesArbitraryParameters(), ""); diff --git a/test/libsolidity/semanticTests/functionCall/call_internal_function_via_expression.sol b/test/libsolidity/semanticTests/functionCall/call_internal_function_via_expression.sol new file mode 100644 index 000000000..ebe52b3e5 --- /dev/null +++ b/test/libsolidity/semanticTests/functionCall/call_internal_function_via_expression.sol @@ -0,0 +1,24 @@ +contract C { + function foo() internal returns (uint) { + return 42; + } + + function get_ptr(function() internal returns (uint) ptr) internal returns(function() internal returns (uint)) { + return ptr; + } + + function associated() public returns (uint) { + // This expression directly references function definition + return (foo)(); + } + + function unassociated() public returns (uint) { + // This expression is not associated with a specific function definition + return (get_ptr(foo))(); + } +} +// ==== +// compileViaYul: also +// ---- +// associated() -> 42 +// unassociated() -> 42