-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about shadowing state variables #973
Comments
👍🏼 |
+100 Another example using a "named return" related to #718
And another:
One more:
Fortunately this doesn't compile:
|
Got burned by this. Lost 20 minutes or so. Added a global variable to a contract I'd not been working on for a few days and forgot that that variable name was already used inside a function. |
I think we should add a warning for shadowing "globals". |
This is implemented now. |
Unsolved questions:
We have to keep in mind that we want to have identifiers at global level at some point, but I think it is still fine because we have qualified import statements.
The following is valid Solidity code:
I propose that the compiler should not allow function-level variables to be named identically to contract-level variables.
In other languages, such as Java, this would be valid code because you can differentiate between fields and local variables using the
this
keyword. In Solidity, however, this is an issue becausethis
has a different purpose and accessingthis.*
will spawn an external call, which would probably not be expected behaviour.In addition to this, this behaviour is confusing for people who are starting out with the language.
The text was updated successfully, but these errors were encountered: