Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABIEncoderV2 public functions with struct containing multiple members of the same struct type #3275

Closed
naddison36 opened this issue Dec 4, 2017 · 2 comments
Assignees
Labels

Comments

@naddison36
Copy link

naddison36 commented Dec 4, 2017

ABI encoder version 2 does not support public functions with a struct containing multiple members of the same struct type. For example, the below code fails with error TestContract.sol:18:28: TypeError: Internal or recursive type is not allowed for public or external functions.

pragma solidity 0.4.19;
pragma experimental ABIEncoderV2;

contract TestContract
{
    struct SubStruct {
        uint256 id;
        string description;
    }

    struct TestStruct {
        SubStruct subStruct1;
        SubStruct subStruct2;
    }

    TestStruct[] internal tests;

    function addTestStruct(TestStruct testStruct) public
    {
        tests.push(testStruct);
    }
}

If I remove line 13 SubStruct subStruct2; the code does compile using Solidity the 0.4.19 compiler.

The code will also compile if I change line 18 to be internal instead of public function addTestStruct(TestStruct testStruct) internal

My workaround is to declare a second SubStruct

pragma solidity 0.4.19;
pragma experimental ABIEncoderV2;

contract TestContract
{
    struct SubStruct {
        uint256 id;
        string description;
    }

    struct SubStruct2 {
        uint256 id;
        string description;
    }

    struct TestStruct {
        SubStruct subStruct1;
        SubStruct2 subStruct2;
    }

    TestStruct[] internal tests;

    function addTestStruct(TestStruct testStruct) public
    {
        tests.push(testStruct);
    }
}
@chriseth chriseth self-assigned this Dec 4, 2017
@riordant
Copy link

riordant commented Jan 5, 2018

Have the exact same issue.

@attente
Copy link

attente commented Feb 12, 2018

It also occurs if the same struct is embedded multiple times indirectly through composition:

pragma solidity ^0.4.19;
pragma experimental ABIEncoderV2;

contract A {
  struct T {
    U u;
    V v;
  }

  struct U {
    W w;
  }

  struct V {
    W w;
  }

  struct W {
    int x;
  }

  function f(T t) public pure {
  }
}

attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 13, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 27, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 27, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 28, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 28, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Feb 28, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 1, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 1, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 1, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 1, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 1, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 2, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 2, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 3, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 3, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 3, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 4, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 4, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 4, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 4, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 4, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 5, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 5, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 5, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 6, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 6, 2018
@chriseth chriseth added this to To do in 0.5.0 via automation Mar 6, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 6, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 6, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 7, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Mar 7, 2018
@chriseth chriseth added this to To do in 0.4.22 via automation Mar 8, 2018
@chriseth chriseth moved this from To do to In Progress in 0.4.22 Mar 13, 2018
@chriseth chriseth moved this from In Progress to Under Review in 0.4.22 Mar 15, 2018
@axic axic closed this as completed in #3745 Apr 5, 2018
0.5.0 automation moved this from To do to Done Apr 5, 2018
0.4.22 automation moved this from Under Review to Done Apr 5, 2018
attente added a commit to horizon-games/eth-state-channels-research that referenced this issue Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
0.4.22
  
Done
0.5.0
  
Done
Development

No branches or pull requests

4 participants