From e65a5a562e69607756e12e8796b3705afebff074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 23 Apr 2020 21:16:41 +0200 Subject: [PATCH] IRGenerationContext::internalDispatch(): Fix code generated when the function called via pointer does not return anything --- .../codegen/ir/IRGenerationContext.cpp | 3 ++- ...function_returning_nothing_via_pointer.sol | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/semanticTests/functionCall/call_function_returning_nothing_via_pointer.sol diff --git a/libsolidity/codegen/ir/IRGenerationContext.cpp b/libsolidity/codegen/ir/IRGenerationContext.cpp index c3b896ee1..0410d8835 100644 --- a/libsolidity/codegen/ir/IRGenerationContext.cpp +++ b/libsolidity/codegen/ir/IRGenerationContext.cpp @@ -122,7 +122,7 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out) <#cases> case { - := () + () } default { invalid() } @@ -133,6 +133,7 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out) YulUtilFunctions utils(m_evmVersion, m_revertStrings, m_functions); templ("in", suffixedVariableNameList("in_", 0, _in)); templ("arrow", _out > 0 ? "->" : ""); + templ("assignment_op", _out > 0 ? ":=" : ""); templ("out", suffixedVariableNameList("out_", 0, _out)); vector> functions; for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts) diff --git a/test/libsolidity/semanticTests/functionCall/call_function_returning_nothing_via_pointer.sol b/test/libsolidity/semanticTests/functionCall/call_function_returning_nothing_via_pointer.sol new file mode 100644 index 000000000..569d185bd --- /dev/null +++ b/test/libsolidity/semanticTests/functionCall/call_function_returning_nothing_via_pointer.sol @@ -0,0 +1,19 @@ +contract test { + bool public flag = false; + + function f0() public { + flag = true; + } + + function f() public returns (bool) { + function() internal x = f0; + x(); + return flag; + } +} + +// ==== +// compileViaYul: also +// ---- +// f() -> true +// flag() -> true