Commit b5a8691
authored
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`
}1 parent b93cf4b commit b5a8691
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments