When is "!Address.isContract(address(this)) && _initialized == 1" true?

Initializable.sol

    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

In (!Address.isContract(address(this)) && _initialized == 1) I understand that !Address.isContract(address(this)) would be true from a constructor, but how would _initialized == 1 also be true then?

This allows constructors to call initializers. For example, if a contract inherits another contract and both have constructors with initializers, then _initialized == 1 due to the modifier having already been called in the parent constructor. See these two testcases: 1 2 and their test contracts for example.

1 Like