______gap error during contract upgrade

I am facing error related to ______gap.
Here is what I want to do:

  • Deploy ContractA (upgradeable)
  • Deploy ContractB (non-upgradeable)
  • Deploy new ContractA by inheriting ContractB

The github repo link: https://github.com/abhi3700/evm_contracts_contractAB

Here is ContractA.sol,

ContractB: https://github.com/abhi3700/evm_contracts_contractAB/blob/main/contracts/ContractB.sol

ContractANew: https://github.com/abhi3700/evm_contracts_contractAB/blob/main/contracts/ContractANew.sol

During deployment, the error is as follows:

Error: New storage layout is incompatible

contracts/ContractB.sol:27: Replaced `_value` with `_roles` of incompatible type

contracts/ContractB.sol:29: Replaced `______gap` with `initialized` of incompatible type

Can anyone help me please?

1 Like

The problem is that ContractA has its own variables (like _value), and when you inherit ContractB you displace those variables. They are being replaced in the layout with the new ones introduced by ContractB.

The right solution is to write this like: contract ContractANew is ContractA, ContractB.

Okay! understood!
Let me try & get back.

Hey @frangio
I have made your suggested changes.
But, now I am looking for this: "How to inherit a ContractB with constructor inside a upgradeable contract- 'ContractANew'".

Could you please look into the issue?

Problem: I am not able to inherit the "contractB" with a constructor within inside "contractANew".

Any solution to this. If possible, you can probably fork the repo & make corresponding changes.

ContractB should not have a constructor. Use an initializer function. See Writing Upgradeable Contracts.

Got it! I will try myself & get back.