Add a warning about a varialbe of the name of an instruction

This commit is contained in:
Yoichi Hirai
2017-06-13 16:57:08 +02:00
parent a7241df4b7
commit 8775e77305
4 changed files with 28 additions and 1 deletions
@@ -26,6 +26,8 @@
#include <libsolidity/analysis/TypeChecker.h>
#include <libsolidity/interface/ErrorReporter.h>
#include <boost/algorithm/string.hpp>
using namespace std;
namespace dev
@@ -232,6 +234,26 @@ vector<Declaration const*> NameAndTypeResolver::cleanedDeclarations(
return uniqueFunctions;
}
void NameAndTypeResolver::warnVariablesNamedLikeInstructions()
{
for (auto const& instruction: c_instructions)
{
string const instructionName{boost::algorithm::to_lower_copy(instruction.first)};
auto declarations = nameFromCurrentScope(instructionName);
for (Declaration const* const declaration: declarations)
{
solAssert(!!declaration, "");
if (dynamic_cast<MagicVariableDeclaration const* const>(declaration))
// Don't warn the user for what the user did not.
continue;
m_errorReporter.warning(
declaration->location(),
"Variable is shadowed in inline assembly by an instruction of the same name"
);
}
}
}
bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode)
{
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(&_node))