Description
Abstract
Allow a fallback function to use returns.
Motivation
Some YUL programs use return inside fallback, e.g. https://github.com/Zoltu/deterministic-deployment-proxy/blob/49f29698ce95bd510a18cabb94fd8ba4d352d687/source/deterministic-deployment-proxy.yul#L15
I can't easily adapt that behavior in solidity, this is how I worked around it (using return opcode):
fallback() external payable {
address payable createdContract = deploy(msg.data, bytes32(0));
assembly {
mstore(0, createdContract)
return(0, 32)
}
}
function deploy(bytes,bytes32){ /**create2**/ }
Would be good if I could just return the type I want there without using assembly.
Specification
if function is fallback, the call of return could be anything, because it would be directly a opcode call of return, which would be a bytes output.
fallback() external payable returns(bytes memory returnData) {
address payable createdContract = deploy(msg.data, bytes32(0));
returnData = abi.encode(createdContract);
}
Also for contracts that always return the same data type at fallback, they could use returns like any other function:
fallback() external payable returns(address payable createdContract) {
createdContract = deploy(msg.data, bytes32(0));
}
This would not work for receive()
, only for fallback.
Backwards Compatibility
N/A