-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Enforce data location. #4738
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
Enforce data location. #4738
Conversation
| if (!resolveNamesAndTypes(*node, false)) | ||
| { | ||
| success = false; | ||
| break; |
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.
I'm not sure why this was here. I will run the whole test suite once the expectations are all updated, if it does not crash, I would propose to keep it like this.
|
Needs rebasing. |
0ac2a81 to
57293f7
Compare
Codecov Report
@@ Coverage Diff @@
## develop #4738 +/- ##
===========================================
- Coverage 87.79% 87.77% -0.02%
===========================================
Files 314 314
Lines 31107 31159 +52
Branches 3690 3688 -2
===========================================
+ Hits 27310 27351 +41
- Misses 2548 2552 +4
- Partials 1249 1256 +7
|
| return; | ||
|
|
||
| if (_variable.isConstant() && !_variable.isStateVariable()) | ||
| m_errorReporter.declarationError(_variable.location(), "The \"constant\" keyword can only be used for state variables."); |
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.
Is this actually part of this PR?
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.
Previously, the checks were much less restrictive, so the checks would pass here and then the type checker did the rest, but I actually think it is better to have strict tests here and then also move this check here, which I would say is the appropriate place.
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.
Ok perhaps to summarize differently: Other ways to solve this would result in weird error messages.
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.
Actually, to me it seems this check should even be moved up to the SyntaxChecker instead. Using the constant keyword in the wrong place feels like a syntax error to me.
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.
If you agree, I would still like to keep it here. While it can be checked earlier, I think it still "belongs" here, especially when we also add things like mutable and immutable.
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.
I'm fine with keeping it here.
| expectType(*_variable.value(), *varType); | ||
| if (_variable.isConstant()) | ||
| { | ||
| if (!_variable.isStateVariable()) |
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 the place where the constant check was previously.
57293f7 to
5a38b2d
Compare
07ff13c to
6281484
Compare
| if (_typeName.isPayable() && _typeName.visibility() != VariableDeclaration::Visibility::External) | ||
| { | ||
| typeError(_typeName.location(), "Only external function types can be payable."); | ||
| fatalTypeError(_typeName.location(), "Only external function types can be payable."); |
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.
These have to be fatal because otherwise the constructor of FunctionType will assert.
| "Location has to be calldata for external functions " | ||
| "(remove the \"memory\" or \"storage\" keyword)." | ||
| ); | ||
| case Location::Memory: |
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.
Could be pulled up onto the same line and unindented once.
| m_errorReporter.fatalDeclarationError(_location, _description); | ||
| } | ||
|
|
||
| DataLocation ReferencesResolver::variableLocationToDataLocation(VariableDeclaration::Location _varLoc) |
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 unused, should either be used above or removed.
libsolidity/ast/AST.cpp
Outdated
| if (!hasReferenceOrMappingType() || isStateVariable()) | ||
| return set<Location>{ Location::Default }; | ||
|
|
||
| if (isEventParameter()) |
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.
change to else if
libsolidity/ast/AST.cpp
Outdated
| } | ||
| else if (isLocalVariable()) | ||
| { | ||
| // TODO where was this checked in the previous version? |
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.
remove - it was in reference resolver visit.
| { | ||
| "constant" : false, | ||
| "name" : "", | ||
| "scope" : 16, |
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 for adding this to isoltest, @ekpyron ;)
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.
Although it's still a bit hacky, e.g. it's adding the // ---- delimiter above, although it's not needed for ASTJSON tests - but I'll fix all that in 0.5.1.
| @@ -0,0 +1,11 @@ | |||
| library L { | |||
| struct Nested { uint y; } | |||
| // data location specifier in function signature should be optional even if there are multiple choices | |||
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.
Remove comment and also extract the working case.
| @@ -0,0 +1,9 @@ | |||
| contract C { | |||
| // Warning for no data location provided can be silenced with storage or memory. | |||
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.
remove
| @@ -0,0 +1,7 @@ | |||
| contract C { | |||
| // Shows that the warning for no data location provided can be silenced with storage or memory. | |||
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.
remove
6281484 to
6b4837b
Compare
ekpyron
left a comment
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.
Only had a very quick look so far, so for now only two very minor comments.
libsolidity/ast/AST.cpp
Outdated
| if (isReturnParameter()) | ||
| return true; | ||
|
|
||
| std::vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr; |
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.
No need for std::.
libsolidity/ast/AST.cpp
Outdated
| return false; | ||
| if (callable->returnParameterList()) | ||
| for (auto const& variable: callable->returnParameterList()->parameters()) | ||
| std::vector<ASTPointer<VariableDeclaration>> const* returnParameters = nullptr; |
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.
std:: again
6b4837b to
87d4d87
Compare
ekpyron
left a comment
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 would probably have been easier to review, if it was split up into several commits/PRs, but I think it should be fine. I added some minor comments.
| return; | ||
|
|
||
| if (_variable.isConstant() && !_variable.isStateVariable()) | ||
| m_errorReporter.declarationError(_variable.location(), "The \"constant\" keyword can only be used for state variables."); |
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.
Actually, to me it seems this check should even be moved up to the SyntaxChecker instead. Using the constant keyword in the wrong place feels like a syntax error to me.
| @@ -0,0 +1,6 @@ | |||
| library L { | |||
| function g(uint[]) internal pure returns (uint[2]) {} | |||
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 better to remove the function argument here?
| @@ -0,0 +1,6 @@ | |||
| library L { | |||
| function h(uint[]) private pure returns (uint[]) {} | |||
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.
And remove the return value here?
| @@ -0,0 +1,6 @@ | |||
| library L { | |||
| function h(uint[]) public pure returns (uint[]) {} | |||
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.
Probably better to rename the test or split it into two (an return parameter and function parameter version; at the moment I don't see a function parameter version for this, but there is one for private functions).
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.
I actually don't see much point in splitting, but it should probably be two different functions.
| // Warning: (215-260): Function state mutability can be restricted to pure | ||
| // Warning: (265-317): Function state mutability can be restricted to pure | ||
| // Warning: (322-358): Function state mutability can be restricted to view | ||
| // Warning: (47-108): Function state mutability can be restricted to pure |
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 we should get rid of these warnings altogether.
| } | ||
| // ---- | ||
| // TypeError: (30-55): Data location has to be "memory" (or unspecified) for constants. | ||
| // DeclarationError: (30-55): The "constant" keyword can only be used for state variables. |
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 test looks a bit weird to me - what is it actually supposed to test?
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.
Will remove it.
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.
Hm, seems to be an old test. I think I will keep it for now.
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 is one of the few tests that combine 'constant' with params
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.
We could rename it (not sure to what, though), but I'm fine with just keeping it as it is.
| } | ||
| } | ||
| // ---- | ||
| // TypeError: (51-79): Type is required to live outside storage. |
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.
These expectations don't really match the intention of the test I guess - but it's probably good to keep the test - the expectations should properly align with/after #4798. [so nothing to be done here]
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.
Yes, should be in conflict with #4798 so good to keep.
|
OK, hopefully final update. Will squash after review. |
|
Emscripten build fails on travis. |
|
Actually I think that is an argument against using the same version. |
|
That depends on whether it's the lack of a header include or the lack of C++11 support... If it's the former, then yes, if it's the latter, then bumping the minimum required version makes more sense, I would say. |
|
Only read half-way into this, but the problem may be that |
|
Not sure why it works in the other cases, but interestingly, since C++17, there is also an input iterator version of |
|
That's probably right - and I guess newer compiler (resp. STL) versions are forward compatible with C++17, for which |
|
Updated, let's see what travis will do with it. |
|
Build passed. |
|
Why are the circleci linux tests passing and there is a test failure for one of the appveyor builds? Not related to this PR, but weird. |
|
It's actually very weird - the respective test case |
|
Yeah, it sometimes happens that appveyor picks the wrong commit. |
0d3300f to
9ae0138
Compare
9ae0138 to
09bd3b1
Compare
09bd3b1 to
14e116c
Compare
|
Another run... |
Fixes #4382
Fixes #1815