6

After seeing some unexpected compiler results, I've reduced the issue to this tiny example:

The following compiles under 0.4.10 in Remix:

contract StorageMapping {

    struct S {
        mapping(bytes32 => uint) m;
        bytes32[] b;
        uint x;
    }

    mapping(bytes32 => S) public sStructs;

}

However, the following fails to compile with "Internal Type is not allowed for state variable, referring to the mapping. Spot checked 3.x and 2.x. Result is consistent back to version 0.2.1 (0.2.0 throws internal compiler error).

Only difference in the contracts is the one line commented out.

contract StorageMapping {

    struct S {
        mapping(bytes32 => uint) m;
        bytes32[] b;
        // uint x;
    }

    mapping(bytes32 => S) public sStructs;

}

The important thing seems to be to add a simple value to the struct (even if not needed). This makes me wonder what's really going on.

Does anyone know a reason why the mapped struct seems to need at least one simple value to avoid confusion?

2

Thanks to chriseth for pointing out that's not possible to assemble a getter for sStructs when the structs contain only indexed types. Since it is declared public, the compiler is not happy about being asked to create an impossible getter.

Remove public and both flavors and compile.

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.