Issue warning for variables called super or this

This commit is contained in:
Mathias Baumann
2019-05-02 11:30:24 +02:00
parent 00172192bf
commit cf35e5ba02
7 changed files with 42 additions and 28 deletions
+2 -1
View File
@@ -63,7 +63,8 @@ eth::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
BOOST_CHECK(!!sourceUnit);
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
NameAndTypeResolver resolver({}, scopes, errorReporter);
GlobalContext globalContext;
NameAndTypeResolver resolver(globalContext, scopes, errorReporter);
solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
@@ -94,8 +94,7 @@ Declaration const& resolveDeclaration(
bytes compileFirstExpression(
const string& _sourceCode,
vector<vector<string>> _functions = {},
vector<vector<string>> _localVariables = {},
vector<shared_ptr<MagicVariableDeclaration const>> _globalDeclarations = {}
vector<vector<string>> _localVariables = {}
)
{
ASTPointer<SourceUnit> sourceUnit;
@@ -113,15 +112,11 @@ bytes compileFirstExpression(
BOOST_FAIL(msg);
}
vector<Declaration const*> declarations;
declarations.reserve(_globalDeclarations.size() + 1);
for (ASTPointer<Declaration const> const& variable: _globalDeclarations)
declarations.push_back(variable.get());
ErrorList errors;
ErrorReporter errorReporter(errors);
GlobalContext globalContext;
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
NameAndTypeResolver resolver(declarations, scopes, errorReporter);
NameAndTypeResolver resolver(globalContext, scopes, errorReporter);
resolver.registerDeclarations(*sourceUnit);
vector<ContractDefinition const*> inheritanceHierarchy;
@@ -598,10 +593,7 @@ BOOST_AUTO_TEST_CASE(blockhash)
}
)";
auto blockhashFun = TypeProvider::function(strings{"uint256"}, strings{"bytes32"},
FunctionType::Kind::BlockHash, false, StateMutability::View);
bytes code = compileFirstExpression(sourceCode, {}, {}, {make_shared<MagicVariableDeclaration>("blockhash", blockhashFun)});
bytes code = compileFirstExpression(sourceCode, {}, {});
bytes expectation({uint8_t(Instruction::PUSH1), 0x03,
uint8_t(Instruction::BLOCKHASH)});
@@ -617,10 +609,7 @@ BOOST_AUTO_TEST_CASE(gas_left)
}
}
)";
bytes code = compileFirstExpression(
sourceCode, {}, {},
{make_shared<MagicVariableDeclaration>("gasleft", TypeProvider::function(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))}
);
bytes code = compileFirstExpression(sourceCode, {}, {});
bytes expectation = bytes({uint8_t(Instruction::GAS)});
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
@@ -0,0 +1,11 @@
contract C {
function f() pure public {
uint super = 3;
uint this = 4;
}
}
// ----
// Warning: (52-62): This declaration shadows a builtin symbol.
// Warning: (76-85): This declaration shadows a builtin symbol.
// Warning: (52-62): Unused local variable.
// Warning: (76-85): Unused local variable.