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

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

Closed
roschler opened this issue Nov 27, 2018 · 3 comments
Assignees
Labels

Comments

@roschler
Copy link

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

@roschler
Copy link
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

@chriseth
Copy link
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.

@chriseth
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants