diff --git a/docs/060-breaking-changes.rst b/docs/060-breaking-changes.rst index a0b1e76e7..5f906cd19 100644 --- a/docs/060-breaking-changes.rst +++ b/docs/060-breaking-changes.rst @@ -72,7 +72,13 @@ This section highlights changes that affect syntax and semantics. not matching any other function which send value will revert. You should only need to implement the new fallback function if you are following an upgrade or proxy pattern. -* Functions can now only be overridden when they are either marked with the ``virtual`` keyword or defined in an interface. When overriding a function or modifier, the new keyword ``override`` must be used. When overriding a function or modifier defined in multiple parallel bases, all bases must be listed in parentheses after the keyword like so: ``override(Base1, Base2)``. +* Functions can now only be overridden when they are either marked with the + ``virtual`` keyword or defined in an interface. Functions without + implementation outside an interface have to be marked ``virtual``. + When overriding a function or modifier, the new keyword ``override`` + must be used. When overriding a function or modifier defined in multiple + parallel bases, all bases must be listed in parentheses after the keyword + like so: ``override(Base1, Base2)``. How to update your code @@ -98,7 +104,7 @@ This section gives detailed instructions on how to update prior code for every b * Choose unique identifiers for variable declarations in inline assembly that do not conflict with declartions outside the inline assembly block. -* Add ``virtual`` to every non-interface function you intend to override. For single inheritance, add ``override`` to every overriding function. For multiple inheritance, add ``override(A, B, ..)``, where you list all contracts that define the overridden function in the brackets. When multiple bases define the same function, the inheriting contract must override all conflicting functions. +* Add ``virtual`` to every non-interface function you intend to override. Add ``virtual`` to all functions without implementation outside interfaces. For single inheritance, add ``override`` to every overriding function. For multiple inheritance, add ``override(A, B, ..)``, where you list all contracts that define the overridden function in the brackets. When multiple bases define the same function, the inheriting contract must override all conflicting functions. New Features diff --git a/docs/contracts/inheritance.rst b/docs/contracts/inheritance.rst index 6a29f83e0..db947f571 100644 --- a/docs/contracts/inheritance.rst +++ b/docs/contracts/inheritance.rst @@ -6,13 +6,19 @@ Inheritance Solidity supports multiple inheritance including polymorphism. -All function calls are virtual, which means that the most derived function -is called, except when the contract name is explicitly given or the -``super`` keyword is used. - -All functions overriding a base function must specify the ``override`` keyword. +Polymorphism means that a function call (internal and external) +always executes the function of the same name (and parameter types) +in the most derived contract in the inheritance hierarchy. +This has to be explicitly enabled on each function in the +hierarchy using the ``virtual`` and ``override`` keywords. See :ref:`Function Overriding ` for more details. +It is possible to call functions further up in the inheritance +hierarchy internally by explicitly specifying the contract +using ``ContractName.functionName()`` or using ``super.functionName()`` +if you want to call the function one level higher up in +the flattened inheritance hierarchy (see below). + When a contract inherits from other contracts, only a single contract is created on the blockchain, and the code from all the base contracts is compiled into the created contract. This means that all internal calls @@ -248,6 +254,10 @@ overridden when used with multiple inheritance: Functions with the ``private`` visibility cannot be ``virtual``. +.. note:: + + Functions without implementation have to be marked ``virtual`` + outside of interfaces. .. _modifier-overriding: