You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixing Variable Shadowing in Solidity: uint256 Redeclaration Error (#636)
The issue arises because the variable `a` is already declared as a
parameter of the `arithmeticError` function:
```solidity
function arithmeticError(uint256 a) public {
uint256 a = a - 100; // Error: `a` is already declared as a parameter
}
When you redeclare a with uint256 a = a - 100;, the compiler throws an error because you're trying to shadow the parameter a by declaring a new variable with the same name. This is not allowed in Solidity.
To fix this, simply remove the type declaration (uint256) and use the parameter a directly:
solidity
Code kopieren
function arithmeticError(uint256 a) public {
a = a - 100; // Correct: modifies the existing parameter `a`
}
0 commit comments