diff --git a/packages/core/contracts/test/ValidationsInitializer.sol b/packages/core/contracts/test/ValidationsInitializer.sol index 59afbeef6..97a18b714 100644 --- a/packages/core/contracts/test/ValidationsInitializer.sol +++ b/packages/core/contracts/test/ValidationsInitializer.sol @@ -12,11 +12,11 @@ contract Parent_NoInitializer { } contract Parent_InitializerModifier is Initializable { - function parentInit() initializer public {} + function parentInit() initializer internal {} } contract Parent_ReinitializerModifier is Initializable { - function parentReinit() reinitializer(2) public {} + function parentReinit() reinitializer(2) internal {} } contract Parent__OnlyInitializingModifier is Initializable { diff --git a/packages/core/contracts/test/cli/excludes/AbstractUUPS.sol b/packages/core/contracts/test/cli/excludes/AbstractUUPS.sol index 4c8ce4555..8e4a3e554 100644 --- a/packages/core/contracts/test/cli/excludes/AbstractUUPS.sol +++ b/packages/core/contracts/test/cli/excludes/AbstractUUPS.sol @@ -12,7 +12,7 @@ abstract contract AbstractUUPS is UUPSUpgradeable, Abstract1, Abstract2 { z = _z; } - function initialize() onlyInitializing public { + function initialize() initializer public { __UUPSUpgradeable_init(); } } \ No newline at end of file diff --git a/packages/core/contracts/test/cli/excludes/UsesAbstractUUPS.sol b/packages/core/contracts/test/cli/excludes/UsesAbstractUUPS.sol index 426a330d6..4a6f7f76b 100644 --- a/packages/core/contracts/test/cli/excludes/UsesAbstractUUPS.sol +++ b/packages/core/contracts/test/cli/excludes/UsesAbstractUUPS.sol @@ -12,8 +12,4 @@ contract UsesAbstractUUPS is AbstractUUPS { function _authorizeUpgrade(address newImplementation) internal pure override { revert("Upgrade disabled"); } - - function initializeChild() initializer public { - super.initialize(); - } } \ No newline at end of file diff --git a/packages/core/src/validate/run.ts b/packages/core/src/validate/run.ts index 49a13fd74..d4b66275f 100644 --- a/packages/core/src/validate/run.ts +++ b/packages/core/src/validate/run.ts @@ -678,7 +678,7 @@ function* getInitializerErrors( deref('ContractDefinition', base.baseName.referencedDeclaration), ); const baseContractsInitializersMap = new Map( - baseContractDefs.map(base => [base.name, getPossibleInitializers(base)]), + baseContractDefs.map(base => [base.name, getPossibleInitializers(base, { ignorePublicInitializers: true })]), ); const baseContractsWithInitializers = baseContractDefs .filter(base => hasInitializers(base.name, baseContractsInitializersMap)) @@ -773,7 +773,7 @@ function hasInitializers(baseName: string, baseContractsInitializersMap: Map 0; } -function getPossibleInitializers(contractDef: ContractDefinition) { +function getPossibleInitializers(contractDef: ContractDefinition, { ignorePublicInitializers = false } = {}) { const fns = [...findAll('FunctionDefinition', contractDef)]; return fns.filter( fnDef => @@ -781,7 +781,8 @@ function getPossibleInitializers(contractDef: ContractDefinition) { ['initializer', 'reinitializer', 'onlyInitializing'].includes(modifier.modifierName.name), ) || ['initialize', 'initializer', 'reinitialize', 'reinitializer'].includes(fnDef.name)) && - !(fnDef.virtual && !fnDef.body), // Skip virtual functions without a body, since that indicates an abstract function and is not itself an initializer + !(fnDef.virtual && !fnDef.body) && // Skip virtual functions without a body, since that indicates an abstract function and is not itself an initializer + (!ignorePublicInitializers || (fnDef.visibility !== 'public' && fnDef.visibility !== 'external')), // For parent contracts, ignore public initializers since they do not strictly need to be called from the child ); }