3.17 Shadowing & Pre-declaration
Shadowing
Shadowing of built-in Solidity
variables was a concern in some of the older Solidity
versions. Built-in variables such as now
, assert
and some others could be shadowed by other variables, functions or modifiers in the contract to override their behavior.
This as you can imagine is dangerous and could lead to many unexpected behavior and therefore this Shadowing was disallowed in later Solidity
versions.
Similar to the Shadowing of built-in variables the older versions of Solidity
also allowed state variable shadowing.
This meant that the right contracts could have state variables that had the same name as some of their base contracts. You can imagine that the base variables and shadowed variables with the same names could be confusing even for the developer and they could end up using or modifying the wrong variable from the base contracts.
This dangerous and unexpected consequences was recognized, so Solidity
compiler 0.6.0
disallowed Shadowing of state variables.
Pre-declaration
Earlier versions of Solidity
allowed the use of local variables even before they were declared.
These variables could be declared later or they could have been declared in another scope. This led to undefined behavior as you may expect.
Solidity
version 0.5.0
and beyond change this, to implement the popular C99-style scoping rules where variables can only be used after they have been declared and only in the same or nested scopes.
Last updated