diff options
author | Balajiganapathi S <balajiganapathi.s@gmail.com> | 2017-11-18 00:55:07 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-22 10:07:56 +0800 |
commit | d102deaec90f6f5bfe38140b459a05215d3254f9 (patch) | |
tree | a6f8f5df73bbe5454fe472d4d80042d5a071d8d3 /libsolidity/analysis/ConstantEvaluator.cpp | |
parent | c0b49694518d333a8ad62623321f839fc3b4bc6a (diff) | |
download | dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.gz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.bz2 dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.lz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.xz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.zst dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.zip |
Detect cyclic constant definitions
Diffstat (limited to 'libsolidity/analysis/ConstantEvaluator.cpp')
-rw-r--r-- | libsolidity/analysis/ConstantEvaluator.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp index 50044eb6..cb8bbc05 100644 --- a/libsolidity/analysis/ConstantEvaluator.cpp +++ b/libsolidity/analysis/ConstantEvaluator.cpp @@ -77,18 +77,22 @@ void ConstantEvaluator::endVisit(Literal const& _literal) void ConstantEvaluator::endVisit(Identifier const& _identifier) { - VariableDeclaration const *variableDeclaration = dynamic_cast<VariableDeclaration const *>(_identifier.annotation().referencedDeclaration); + VariableDeclaration const* variableDeclaration = dynamic_cast<VariableDeclaration const*>(_identifier.annotation().referencedDeclaration); if (!variableDeclaration) return; if (!variableDeclaration->isConstant()) m_errorReporter.fatalTypeError(_identifier.location(), "Identifier must be declared constant."); ASTPointer<Expression> value = variableDeclaration->value(); - if (value) - { - if (!value->annotation().type) - ConstantEvaluator e(*value, m_errorReporter); + if (!value) + m_errorReporter.fatalTypeError(_identifier.location(), "Constant identifier declaration must have a constant value."); - _identifier.annotation().type = value->annotation().type; + if (!value->annotation().type) + { + if (m_depth > 32) + m_errorReporter.fatalTypeError(_identifier.location(), "Cyclic constant definition."); + ConstantEvaluator e(*value, m_errorReporter, m_depth + 1); } + + _identifier.annotation().type = value->annotation().type; } |