2

When I try compiling the following on Remix:

contract Betting{
    struct Player{
        mapping(uint => uint) amounts;

    }

    struct Match{
        address [] playerAdresses;
        uint [] totalBets;
    }

    mapping(address => Player) public playerInfo;
    mapping(uint => Match) public matchInfo;
}

I get the error TypeError: Internal or recursive type is not allowed for public state for both playerInfo and matchInfo. However when I remove both uint [] totalBets and mapping(uint => uint) amounts these errors go away. Exactly why does that happen?

1

The problem here seems to be with the getters that are created when you declare the variables public, changing the visibility to internal cancels the error. In this answer it is explained that passing nested arrays is the problem.

Note that in both cases adding a fix-length variable to the structs cancels the errors.

Furthermore, the first mapping can be done using:

mapping(address => mapping(uint => uint)) public playerInfo;

Hope this helps.

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.