0

I'm getting the following error:

Data location must be "calldata" for parameter in external function, but "memory" was given.

for the following function:

    function _registerAirline(address addr, string memory name)
        external
        requireIsOperational
    {
        require(!airlines[addr].isRegistered, "Airline is already registered");

        airlines[addr] = Airline({
            name: name,
            isFunded: false,
            isRegistered: true
        });

        multiSig.push(addr);
        emit AirlineRegistered(
            airlines[addr].name,
            airlines[addr].isFunded,
            airlines[addr].isRegistered
        );
    }

But, when I change the string memory name to string calldata name and compile, I get an error:

ParserError: Expected ',' but got identifier
function _registerAirline(address addr, bytes calldata name)
                                                       ^--^
2
  • 1
    What version of solidity are you using? At least 0.6.7 and 0.5.17 work as expected and they do not generate that error message.
    – Ismael
    May 23, 2020 at 1:59
  • 1
    full code of contract will give more idea on error because changing memory to calldata work for me fine without error. May 23, 2020 at 3:44

1 Answer 1

2

I assume you were using solidity 0.4.x. Explicitness of parameters data location was added in 0.5.x. Change bytes calldata name to bytes name and it should compile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.