-
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 if shadowing built-ins #1637
Conversation
|
||
for (Declaration const* declaration: m_globals) | ||
if (declaration->name() == _function.name()) | ||
warning(_function.location(), "Shadowing global function \"" + _function.name() + "\"."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it is better to say "Shadowing builtin function".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not have to be a function. What about builtin symbol
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is within visit(FunctionDefinition)
, but using builtin symbol
for both cases is fine.
for (Declaration const* declaration: m_globals) | ||
if (declaration->name() == _variable.name()) | ||
warning(_variable.location(), "Shadowing global variable \"" + _variable.name() + "\"."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it is better to say "Shadowing builtin variable".
@@ -49,6 +50,11 @@ void StaticAnalyzer::endVisit(ContractDefinition const&) | |||
bool StaticAnalyzer::visit(FunctionDefinition const& _function) | |||
{ | |||
m_nonPayablePublic = _function.isPublic() && !_function.isPayable(); | |||
|
|||
for (Declaration const* declaration: m_globals) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriseth any idea why here m_globals.size() == 0
, while in the constructor it is still 18?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it was only a problem on my computer, it seems to work on AppVeyor.
cc0f4e0
to
bdd5614
Compare
@@ -93,7 +93,7 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false, | |||
} | |||
if (success) | |||
{ | |||
StaticAnalyzer staticAnalyzer(errors); | |||
StaticAnalyzer staticAnalyzer(globalContext->declartions(), errors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declarations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, there's still that other issue, at least on my computer.
bdd5614
to
d287927
Compare
Status: tests fail on Linux, but succeed on Windows. |
befa226
to
14a69d7
Compare
No idea why the original |
Did you consider adding this code into |
14a69d7
to
9942714
Compare
Fixed the event and import case.
@chriseth Why should |
429d303
to
e0dba9d
Compare
@axic it is not about static analyzer. The main design problem is that the scopes are not persisted in the AST annotations. |
I'm not sure what is going on, for me it works on mac and linux (ubuntu), but travis fails at without any message:
|
fd13d00
to
21e2cdb
Compare
I think the scope issue which could affect this is members of a struct. |
} | ||
} | ||
)"; | ||
CHECK_WARNING(text, "Shadowing builtin symbol"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo, this should be successful.
I think it is better to add this change to |
BOOST_AUTO_TEST_CASE(shadowing_builtins_with_imports) | ||
{ | ||
char const* text = R"( | ||
import * as msg from "B.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps also add something like import {msg, block} as X from "B.sol"
- that should also be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like that notation is broken currently:
Error: Expected "from".
import {msg, block} as X from "B.sol"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parser has this comment:
// import "abc" [as x];
// import * as x from "abc";
// import {a as b, c} from "abc";
import {msg, block} from "B.sol";
works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. I meant import * as X from "B.sol"
.
ac5e613
to
72fea3b
Compare
72fea3b
to
9c39439
Compare
9c39439
to
4456984
Compare
Rebased for good measure. |
@roadriverrail would you be interested in looking into this? |
4456984
to
5d199cf
Compare
@axic Yes, I'll look into this soon. |
5d199cf
to
ef47139
Compare
Similarly, I've gone ahead and done a rebase of this one, but I can't push to the repository. Once we get that sorted, I can take on the comments @chriseth left. |
@roadriverrail what is your progress on this? I would like to include this feature in the next version which can hopefully happen on monday. |
ef47139
to
d273111
Compare
We cannot really test imports inside this testing framework. |
aec796f
to
225768b
Compare
@chriseth is this ready? Needs to be rebased. |
225768b
to
e0dc74b
Compare
Yes, this is ready. |
@chriseth you need to approve and merge |
Fixes #1249.