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

Fix Hardhat compile error when public variables are used to implement interface functions #1055

Merged
merged 7 commits into from
Jul 31, 2024

Conversation

ericglau
Copy link
Member

@ericglau ericglau commented Jul 30, 2024

When modifying solc input to extract namespaced storage layouts, interface functions are kept (because constants might refer to their function selectors), but we effectively remove state variables (by converting them to dummy enums).

If an interface has a function, which is implemented using a state variable to provide a public getter, then this causes a compile error because the modified solc input (with state variable converted to dummy enum) would no longer have the public getter.

We can resolve this by converting all contracts in the modified solc input to abstract.

Fixes #1053

@ericglau ericglau requested a review from a team July 30, 2024 20:03
Copy link
Contributor

@Amxx Amxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried something like

contract HasExternalViewFunction {
    uint256 public foo;
    bytes4 constant USING_INTERFACE_FUNCTION_SELECTOR = this.foo.selector;
}

would be an issue, but apparently this is not valid solidity.

this is valid, but since its not constant I'm guessing it get removed, right?

    bytes4 immutable USING_INTERFACE_FUNCTION_SELECTOR = this.foo.selector;

@ericglau
Copy link
Member Author

ericglau commented Jul 31, 2024

Added a testcase for the above.

Immutables are effectively removed. Since we are converting all contracts to abstract now, removing immutables also avoids the following from being an issue:

contract DeploysContractToImmutable {
    MyContract public immutable myContract = new MyContract();
}

@ericglau ericglau merged commit 13b6c12 into OpenZeppelin:master Jul 31, 2024
11 checks passed
@ericglau ericglau deleted the 1053 branch July 31, 2024 13:40
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 this pull request may close these issues.

Failed to compile modified contracts for namespaced storage, missing implementation
2 participants