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

UnexpectedCharacter
  • 852
  • 1
  • 11
  • 30
  • 3
    So listen to the warning - interface functions must be external, hence their implementation (in a contract) must be external too. – goodvibration Feb 13 '19 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 '19 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 '19 at 12:55
  • @RoscoKalis the question evolve. And the problem is that I cant fix the error and the warning at the same time. First I have a error, i solve but now I have a warning. Is there a way to fix this error/warning?? – UnexpectedCharacter Feb 13 '19 at 13:01
  • 2
    @AnAllergyToAnalogy: No, it's in 0.4.x as well (and probably in every version back to the initial one). – goodvibration Feb 13 '19 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 '19 at 13:16
  • If I put bouth external(the interface and the implementation). The contract deploy but i can´t call the function internally in the same contract. So the external(interface) public(implementation) is the option that I need. I have to ignore the warning – UnexpectedCharacter Feb 13 '19 at 13:41
  • @goodvibration you're right in 0.4.x it gave a warning but would still compile, whereas in 0.5.x it will actually give a TypeError. Which is not to say your advice was bad or incorrect, just that in version 0.4.x it was recommended (ie, should) rather than mandatory (ie, must). Pointless semantics, I know. – AnAllergyToAnalogy Feb 14 '19 at 06:44

1 Answers1

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[]).

Daniel Portugal
  • 728
  • 4
  • 9