Skip to content

Nested structs that are part of a mapping no longer compile with 0.5.0 (Test repo link included) #5520

Closed

Description

@roschler

With the 5.0 version of solc, if a host struct nests another struct, and the host struct is the value in a mapping, the compiler emits a fatal compilation error using the UnimplementedFeature error code. This code did work in version v0.4.21.

UnimplementedFeatureError: Encoding type "struct TestNestedStructInMapping.structNested memory" not yet implemented.
Compilation failed. See above.
Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2)
Solidity v0.5.0 (solc-js)
Node v8.11.1

Here is a link to a public repo with a minimal project that demonstrates the error:

https://github.com/roschler/nested-structs-tests.git

Activity

  1. roschler commented on Nov 27, 2018

    @roschler
    Author

    It does appear to be a breaking change. For a workaround see the reply to this Stack Exchange post:

    https://ethereum.stackexchange.com/questions/63149/nested-structs-that-are-part-of-a-mapping-broken-in-solidity-0-5-0/63152#63152

  2. chriseth commented on Nov 28, 2018

    @chriseth
    Contributor

    The code in question is

    contract TestNestedStructInMapping {
    
        // The struct that is nested.
        struct structNested {
            uint dummy;
        }
    
        // The struct that holds the nested struct.
        struct structMain {
            structNested gamePaymentsSummary;
        }
    
        // The map that maps a game ID to a specific game.
        mapping(uint256 => structMain) public s_mapOfNestedStructs;
    }
    

    and it indeed seems to work in 0.4.25. Adding another variable to the struct, though, still not makes 0.4.25 complain, but the generated code is wrong - it only returns 32 bytes instead of 64.

    I would propose to fix the internal compiler error by another check in the type checker - if possible.

  3. chriseth commented on Nov 28, 2018

    @chriseth
    Contributor

    So to summarize: The reason this worked in 0.4.25 was by mere coincidence, looking at the code, nested structs in public getter functions were never meant to be supported.

  4. self-assigned this
    on Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions