Skip to content

contract warns if fallback payable is defined without receive defined #10159

Closed as not planned
@3esmit

Description

@3esmit

Description

I'm having to include this

    /**
     * @notice Fails on calls with no `msg.data` but with `msg.value`
     */
    receive() external payable {
        revert("bad call");
    }

into the smart contract so it stops warning me about not using receive. I use fallback payable, but I need msg.data, so receive()(calls with no msg.data, but msg.value) should always fail if I didn't defined a receive() function

This warning is not fair: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.

If I add this receive function, that only reverts, than compiler will include it on the ABI of the contract. But this conflics with the warning and with https://solidity.readthedocs.io/en/v0.7.4/security-considerations.html#take-warnings-seriously

Instead, I added the first line of fallback as require(msg.data.length > 0, "bad call").

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed due inactivityThe issue/PR was automatically closed due to inactivity.language design :rage4:Any changes to the language, e.g. new featureslow effortThere is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.staleThe issue/PR was marked as stale because it has been open for too long.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions