Skip to content

Commit b5a8691

Browse files
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

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract TestContract is Test {
3838
3939
contract ErrorsTest {
4040
function arithmeticError(uint256 a) public {
41-
uint256 a = a - 100;
41+
a = a - 100;
4242
}
4343
}
4444
```

0 commit comments

Comments
 (0)