ERC721PresetMinterPauserAutoIdUpgradeable complains about my Initializer-function

I see a weird behaviour when deriving a contract from ERC721PresetMinterPauserAutoIdUpgradeable:

contract MyNFT is Initializable, ERC721PresetMinterPauserAutoIdUpgradeable
{
    function initialize(        
        string memory name,
        string memory symbol,
        string memory baseTokenURI
    ) public initializer {
        __AccessControlEnumerable_init_unchained();
        __ERC721PresetMinterPauserAutoId_init(name, symbol, baseTokenURI);
    }

}

Compiling this contract gives an error:

TypeError: Overriding function is missing "override" specifier.
  --> contracts/MyNFT.sol:41:5:
   |
41 |     function initialize(        
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> @openzeppelin/contracts-upgradeable/token/ERC721/presets/ERC721PresetMinterPauserAutoIdUpgradeable.sol:39:5:
   |
39 |     function initialize(
   |     ^ (Relevant source part starts here and spans across multiple lines).

Is override really necessary? Couldn't find anything regarding this. As far as I know the iniailizer-methods are handled differently and are not overriding themselfs.

ERC721PresetMinterPauserAutoIdUpgradeable defines the initialize() function as virtual.

function initialize(
        string memory name,
        string memory symbol,
        string memory baseTokenURI
    ) public virtual initializer

if you extend your contract with it and want to implement a virtual function with the same name and parameters, then yes, you will have to use the override keyword.

1 Like