-
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
Enforce data location. #4738
Enforce data location. #4738
Conversation
@@ -297,7 +297,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res | |||
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
|
@@ -297,6 +303,9 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable) | |||
if (_variable.annotation().type) | |||
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.
@@ -708,8 +708,6 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) | |||
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
return; | ||
} | ||
|
||
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.
@@ -454,3 +432,21 @@ void ReferencesResolver::fatalDeclarationError(SourceLocation const& _location, | |||
m_errorOccurred = true; | |||
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.
@@ -100,7 +100,7 @@ | |||
{ | |||
"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
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
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