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

Allow mapping to struct with dynamically-sized type to implement inherited function #8489

Closed
travs opened this issue Mar 12, 2020 · 6 comments · Fixed by #8491
Closed

Allow mapping to struct with dynamically-sized type to implement inherited function #8489

travs opened this issue Mar 12, 2020 · 6 comments · Fixed by #8491
Assignees
Milestone

Comments

@travs
Copy link
Contributor

travs commented Mar 12, 2020

Overriding functions defined in interfaces with the automatically-generated getters from public state variables usually work great. This was reported in a previous issue (#3514) and fixed.

However, when the return type is a struct that has a dynamically-sized type, like the string in the example below, the generated getter doesn't override properly, causing a compiler error.

// sample.sol
pragma solidity 0.6.4;
pragma experimental ABIEncoderV2;

interface IA {
    struct Baz {
        address a;
        address b;
        string  c;
    }

    function bazMap(address) external returns (Baz memory);
}

contract A is IA {
    mapping (address => Baz) public override bazMap;
}
$ solc sample.sol  # it's version 0.6.4
Error: Overriding public state variable return types differ.
  --> sample.sol:15:5:
   |
15 |     mapping (address => Baz) public override bazMap;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Overridden function is here:
  --> sample.sol:11:5:
   |
11 |     function bazMap(address) external returns (Baz memory);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Based on the docs, I might expect the function to override to be like:

function bazMap(address) external returns (address,address)

but that doesn't work either.

Related to: #6337, #3514, #7521, #4244

@ekpyron
Copy link
Member

ekpyron commented Mar 13, 2020

Thanks for reporting! I just confirmed this and will look into fixing it.

@ekpyron
Copy link
Member

ekpyron commented Mar 13, 2020

This should be "fixed" by #8491.
Once merged, in your example you could do:

pragma solidity 0.6.4;
pragma experimental ABIEncoderV2;

interface IA {
    struct Baz {
        address a;
        address b;
        string  c;
    }

    function bazMap(address) external returns (address, address, string memory);
}

contract A is IA {
    mapping (address => Baz) public override bazMap;
}

To change this to overriding returns (Baz memory) is tracked in #6337, but that's a breaking change unfortunately.

@chriseth
Copy link
Contributor

I'm closing this.

@0xDEnYO
Copy link

0xDEnYO commented Sep 14, 2021

Hey Guys,

I am still facing the same problem. Not sure if I am missing something.

Lets keep this example (though I am using solc 0.8.4):

pragma solidity 0.8.4;

interface IA {
    struct Baz {
        address a;
        address b;
        string  c;
    }

    function bazMap(address) external returns (address, address, string memory);
}

contract A is IA {
    mapping (address => Baz) public override bazMap;
}

If I do it this way and I access one member of bazMap. then its not possible to access member.a cause the compiler doesnt know that this member has this attribute. Even if I write:
function bazMap(address) external returns (address a, address b, string memory c);

Still not possible.

What am I missing?
Also the following approach to let the mapping return a type that is known in/by the interface doesnt work:

contract A is IA {
    mapping (address => IA.Baz) public override bazMap;
}

Compiler says return types differ. But they dont, they are exactly the same and get even referenced with their origin. Dont really understand how to implement this.

@chriseth
Copy link
Contributor

Please ask this question either in ethereum stackexchange or the solidity channel on matrix - this issue is not the right place.
I also don't really understand what you want to achieve. Both your examples compile for me.

@cameel
Copy link
Member

cameel commented Sep 14, 2021

Here's a related issue that's still open: #11826.

@danielb1986 If you have a snippet that produces a compilation error and you think it's a bug (rather than just incorrect usage), you could post it there. Please use a complete example though - you said that accessing some members causes errors but I don't see that in your example and we're left guessing what might be happening.

If you're unsure, drop by at the #solidity channel so that we can discuss it first.

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

Successfully merging a pull request may close this issue.

6 participants