diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index b28034f83..e062a6471 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1121,6 +1121,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) "))\n"; IRVariable selectorVariable(m_context.newYulVariable(), *TypeProvider::fixedBytes(4)); define(selectorVariable, hashVariable); + selector = selectorVariable.name(); m_code << "mstore(" << to_string(CompilerUtils::freeMemoryPointer) << ", " << freeMemoryPre << ")\n"; } } diff --git a/test/libsolidity/semanticTests/specialFunctions/abi_encode_with_signature_from_string.sol b/test/libsolidity/semanticTests/specialFunctions/abi_encode_with_signature_from_string.sol new file mode 100644 index 000000000..7598d382a --- /dev/null +++ b/test/libsolidity/semanticTests/specialFunctions/abi_encode_with_signature_from_string.sol @@ -0,0 +1,15 @@ +contract C { + function f() public pure returns (bytes memory r1, bytes memory r2) { + string memory x = "my_signature"; + r1 = abi.encodeWithSignature("my_signature", 1); + r2 = abi.encodeWithSignature(x, 1); + assert(r1.length == r2.length); + for (uint i = 0; i < r1.length; i++) + assert(r1[i] == r2[i]); + } +} +// ==== +// compileToEwasm: false +// compileViaYul: also +// ---- +// f() -> 0x40, 0xa0, 0x24, -813742827273327954027712588510533233455028711326166692885570228492575965184, 26959946667150639794667015087019630673637144422540572481103610249216, 0x24, -813742827273327954027712588510533233455028711326166692885570228492575965184, 26959946667150639794667015087019630673637144422540572481103610249216