This bounty is no longer available
Web3 DAO | Ethereum Foundation Logo

Error message about disallowed argument location should explain why the location is not allowed

Organization

Ethereum Foundation

Deadline

N/A

Status

ENDED


INSTRUCTIONS

When compiling the following contract with solc v0.8.7:

pragma solidity ^0.8.0;

contract Test {
    struct MyStruct {
        uint256 a;
    }
    
    function foo(MyStruct storage bar) public;
}

we get the following error message:

TypeError: Data location must be "memory" or "calldata" for parameter in function, but "storage" was given.
    function foo(MyStruct storage bar) public;
                 ^------------------^

This is not particularly helpful as functions can actually receive storage arguments, but only if they are internal or private. The error message is not particularly insightful on this distinction, nor helps the developer achieve their task.

Suggestion

A simple improvement could be:

Data location must be "memory" or "calldata" for parameter in "public" or "external" function

Even better, a suggestion could be appended at the end:

TypeError: Data location must be "memory" or "calldata" for parameter in "public" or "external" function, but 
"storage" was given.
    function foo(MyStruct storage bar) public;
                 ^------------------^

Use "internal" or "private" functions to pass storage pointers.