0

I have this interface:

pragma solidity ^0.4.24;
interface EventsInterface 
{
   function removeValueFromArray(uint _userId, uint[] array) external 
   returns(uint[]);
}

And this contract:

pragma solidity ^0.4.24;

import "./EventsInterface.sol";

contract EventsImpl is EventsInterface {

    function removeValueFromArray(uint _userId, uint[] _array) internal returns(uint[]) {

    uint[] storage auxArray;

    for (uint i = 0; i < _array.length; i++){
        if(_array[i] != _userId)
            auxArray.push(_array[i]);
    }

    return auxArray;
}
}

When I try to deploy de contract. Remix report me a error:

This contract does not implement all functions and thus cannot be created.

Changing to public the Impl function:

function removeValueFromArray(uint _userId, uint[] _array) public returns(uint[]) {

    uint[] storage auxArray;

    for (uint i = 0; i < _array.length; i++){
        if(_array[i] != _userId)
            auxArray.push(_array[i]);
    }

    return auxArray;
}

I get the following error

TypeError: Function overload clash during conversion to external types for arguments

To fix the issue I set to public bouth functions (Interface/Implementation) and works. But I getting one warning that tell me that interface function must be external and not public

  • 3
    So listen to the warning - interface functions must be external, hence their implementation (in a contract) must be external too. – goodvibration Feb 13 at 12:37
  • 1
    @goodvibration I believe the restriction of interface functions being external-only is from 0.5.0, but this person is using 0.4.24? – AnAllergyToAnalogy Feb 13 at 12:40
  • 1
    It sounds like you fixed the errors already and are just getting a warning that you can choose to follow or ignore. What is the question right now? – Rosco Kalis Feb 13 at 12:55
  • 2
    @AnAllergyToAnalogy: No, it's in 0.4.x as well (and probably in every version back to the initial one). – goodvibration Feb 13 at 13:09
  • 1
    So if you make both the function in the interface and the implementation external, it still doesn't work? – Rosco Kalis Feb 13 at 13:16
1

Considering you actually need this function to be internal, you could use just inheritance instead of interface:

pragma solidity 0.4.24;

contract EventsInterface 
{
   function removeValueFromArray(uint _userId, uint[] memory _array) internal returns(uint[] memory);
}

contract EventsImpl is EventsInterface {
    uint[] baseArray;

    function removeValueFromArray(uint _userId, uint[] memory _array) internal returns(uint[] memory) {
        uint[] storage auxArray = baseArray;

        for (uint i = 0; i < _array.length; i++){
            if(_array[i] != _userId)
                auxArray.push(_array[i]);
        }

        return auxArray;
    }
}

This contract will compile with version 0.4.24 and with version 0.5.4, too.

Note that you must set the location of a few variables (namely the original array and the returned uint[]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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