1

In the first contract I have:

function getArray() external view returns(uint[] memory result) {
    uint counter = 0;
    result = new uint[](3);
    for (uint i = 0; i <= 3; i++) {
        result[counter] = i;
        counter++;
    }
}

In the second contract I have somewhere:

uint[] r = contractA.getArray();

I receive

TypeError: Type inaccessible dynamic type is not implicitly convertible to expected type uint256[] storage pointer.
  • 1
    You can now do the above without errors. This was added in Solidity version 0.4.22 – willjgriff Sep 28 '18 at 3:06
3

Check out this Github Issue. It seems the EVM can't handle dynamic return types from external functions yet. So as it is this just isn't possible.

However, since you're actually returning a static array of size 3, you can alter the code like this, although you're limited to an array of a specified size:

function getArray() external view returns(uint[3] memory result) {
    uint counter = 0;
    for (uint i = 0; i <= 3; i++) {
        result[counter] = i;
        counter++;
    }
}

And in the separate contract do:

uint[3] memory r = contractA.getArray();

Edit: Since the Byzantium hardfork the EVM is capable of handling dynamic return types from external functions. However, it doesn't seem to be implemented in Solidity yet. This open Github Issue will hopefully enable it. We may be able to experiment with it using pragma experimental ABIEncoderV2; before it's released, although I don't think we can yet.

| improve this answer | |
0

You can write the program as follows:

function getArray() external view returns(uint[] memory result) {
    uint[] result;
    for (uint i = 0; i <= 3; i++)
        result.push(i);
}
| improve this answer | |

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.