diff options
author | Federico Bond <federicobond@gmail.com> | 2016-12-13 10:59:53 +0800 |
---|---|---|
committer | Federico Bond <federicobond@gmail.com> | 2016-12-13 11:32:37 +0800 |
commit | de720e643d8c54c613356bfcdcb6c49984460a17 (patch) | |
tree | 68cf22d6ab999f316ff3ec967029015b3aae6df5 /libsolidity/analysis | |
parent | 1c3605362d6018f5ab72cc84c7511fb49c15d126 (diff) | |
download | dexon-solidity-de720e643d8c54c613356bfcdcb6c49984460a17.tar.gz dexon-solidity-de720e643d8c54c613356bfcdcb6c49984460a17.tar.zst dexon-solidity-de720e643d8c54c613356bfcdcb6c49984460a17.zip |
Improve error message when trying to modify constant variables
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 7235b57a..e414e27c 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1529,6 +1529,8 @@ bool TypeChecker::visit(Identifier const& _identifier) !!annotation.referencedDeclaration, "Referenced declaration is null after overload resolution." ); + auto variableDeclaration = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration); + annotation.isConstant = variableDeclaration != nullptr && variableDeclaration->isConstant(); annotation.isLValue = annotation.referencedDeclaration->isLValue(); annotation.type = annotation.referencedDeclaration->type(); if (!annotation.type) @@ -1612,7 +1614,10 @@ void TypeChecker::requireLValue(Expression const& _expression) { _expression.annotation().lValueRequested = true; _expression.accept(*this); - if (!_expression.annotation().isLValue) + + if (_expression.annotation().isConstant) + typeError(_expression.location(), "Cannot assign to a constant variable."); + else if (!_expression.annotation().isLValue) typeError(_expression.location(), "Expression has to be an lvalue."); } |