diff options
author | chriseth <chris@ethereum.org> | 2017-06-24 00:55:47 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-06-24 02:12:22 +0800 |
commit | 5a75581f6643a229ab12a861d0b0663ea3e5158e (patch) | |
tree | 729d81a12ee3aefe88a41abfc9d890f30a35edde /libsolidity | |
parent | b83f77e0e567b58c2ada831e526ad5bacfed8b40 (diff) | |
download | dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar.gz dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar.bz2 dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar.lz dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar.xz dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.tar.zst dexon-solidity-5a75581f6643a229ab12a861d0b0663ea3e5158e.zip |
Disallow invoking the same modifier multiple times.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 13 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerContext.cpp | 1 | ||||
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 4 |
3 files changed, 18 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 40853608..e1d90e68 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -466,13 +466,26 @@ bool TypeChecker::visit(FunctionDefinition const& _function) var->accept(*this); } + set<Declaration const*> modifiers; for (ASTPointer<ModifierInvocation> const& modifier: _function.modifiers()) + { visitManually( *modifier, _function.isConstructor() ? dynamic_cast<ContractDefinition const&>(*_function.scope()).annotation().linearizedBaseContracts : vector<ContractDefinition const*>() ); + Declaration const* decl = &dereference(*modifier->name()); + if (modifiers.count(decl)) + { + if (dynamic_cast<ContractDefinition const*>(decl)) + m_errorReporter.declarationError(modifier->location(), "Base constructor already provided."); + else + m_errorReporter.declarationError(modifier->location(), "Modifier already used for this function."); + } + else + modifiers.insert(decl); + } if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface) { if (_function.isImplemented()) diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 9d0d6d37..729fb9cc 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -124,6 +124,7 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent) { solAssert(m_asm->deposit() >= 0 && unsigned(m_asm->deposit()) >= _offsetToCurrent, ""); + solAssert(m_localVariables.count(&_declaration) == 0, "Variable already present"); m_localVariables[&_declaration] = unsigned(m_asm->deposit()) - _offsetToCurrent; } diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index dc090634..8724521b 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -879,6 +879,7 @@ void ContractCompiler::appendModifierOrFunctionCode() solAssert(m_currentFunction, ""); unsigned stackSurplus = 0; Block const* codeBlock = nullptr; + vector<VariableDeclaration const*> addedVariables; m_modifierDepth++; @@ -902,6 +903,7 @@ void ContractCompiler::appendModifierOrFunctionCode() for (unsigned i = 0; i < modifier.parameters().size(); ++i) { m_context.addVariable(*modifier.parameters()[i]); + addedVariables.push_back(modifier.parameters()[i].get()); compileExpression( *modifierInvocation->arguments()[i], modifier.parameters()[i]->annotation().type @@ -928,6 +930,8 @@ void ContractCompiler::appendModifierOrFunctionCode() m_returnTags.pop_back(); CompilerUtils(m_context).popStackSlots(stackSurplus); + for (auto var: addedVariables) + m_context.removeVariable(*var); } m_modifierDepth--; } |