5

Why does the function below return [[1, 2], [2, 3]] instead of the expected [[1, 2], [3, 4]]? Tested in browser-solidity.

contract Contract {
    function test() constant returns(uint8[2], uint8[2]){
        uint8[2] memory a = [1, 2];
        uint8[2] memory b = [3, 4];
        return (a, b);
    }
}

Returning a fixed-length array as the first element in the return tuple appears to throw off the indexed memory location of the following elements, regardless of their type:

function test() constant returns(uint8[2], uint8) {
    uint8[2] memory a = [1, 2];
    uint8 b = 3;
    return (a, b); // WRONG: [[1, 2], 2]
}

This is also confusing:

function test() constant returns(uint8[4], uint8) {
    uint8[4] memory a = [1, 2, 3, 4];
    uint8 b = 3;
    return (a, b); // WRONG: [[1, 2, 3, 4], 2]
}
3

I do get the expected values:

  [ [ { [String: '1'] s: 1, e: 0, c: [Object] },
      { [String: '2'] s: 1, e: 0, c: [Object] } ],
    [ { [String: '3'] s: 1, e: 0, c: [Object] },
      { [String: '4'] s: 1, e: 0, c: [Object] } ] ]
  [ [ { [String: '1'] s: 1, e: 0, c: [Object] },
      { [String: '2'] s: 1, e: 0, c: [Object] } ],
    { [String: '3'] s: 1, e: 0, c: [ 3 ] } ]
  [ [ { [String: '1'] s: 1, e: 0, c: [Object] },
      { [String: '2'] s: 1, e: 0, c: [Object] },
      { [String: '3'] s: 1, e: 0, c: [Object] },
      { [String: '4'] s: 1, e: 0, c: [Object] } ],
    { [String: '3'] s: 1, e: 0, c: [ 3 ] } ]
  • 3
    What environment? I tested mine in browser solidity. – Raine Revere Aug 19 '16 at 15:58

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.