added warning for noninitialized references in storage.

This commit is contained in:
LianaHus
2015-10-02 12:38:48 +02:00
parent 6712437e6b
commit fe2b9a3b3c
4 changed files with 49 additions and 15 deletions
+1 -2
View File
@@ -31,13 +31,13 @@ namespace dev
{
namespace solidity
{
struct Error: virtual Exception {};
struct ParserError: virtual Error {};
struct TypeError: virtual Error {};
struct DeclarationError: virtual Error {};
struct DocstringParsingError: virtual Error {};
struct Warning: virtual Error {};
struct CompilerError: virtual Exception {};
struct InternalCompilerError: virtual Exception {};
@@ -53,7 +53,6 @@ public:
infos.push_back(std::make_pair(_errMsg, _sourceLocation));
return *this;
}
std::vector<errorSourceLocationInfo> infos;
};
+20 -2
View File
@@ -43,8 +43,14 @@ bool TypeChecker::checkTypeRequirements(const ContractDefinition& _contract)
if (m_errors.empty())
throw; // Something is weird here, rather throw again.
}
return m_errors.empty();
bool success = m_errors.empty();
for (auto const& it: m_errors)
if (!dynamic_cast<Warning const*>(it.get()))
{
success = false;
break;
}
return success;
}
TypePointer const& TypeChecker::type(Expression const& _expression) const
@@ -443,6 +449,18 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
{
if (_variable.value())
expectType(*_variable.value(), *varType);
else
{
if (auto ref = dynamic_cast<ReferenceType const *>(varType.get()))
if (ref->dataStoredIn(DataLocation::Storage) && _variable.isLocalVariable() && !_variable.isCallableParameter())
{
auto err = make_shared<Warning>();
*err <<
errinfo_sourceLocation(_variable.location()) <<
errinfo_comment("Uninitialized storage pointer. Did you mean '" + varType->toString(true) + " memory'?");
m_errors.push_back(err);
}
}
}
else
{
+5 -2
View File
@@ -43,10 +43,10 @@ class TypeChecker: private ASTConstVisitor
{
public:
/// Performs type checking on the given contract and all of its sub-nodes.
/// @returns true iff all checks passed.
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings
bool checkTypeRequirements(ContractDefinition const& _contract);
/// @returns the list of errors found during type checking.
/// @returns the list of errors and warnings found during type checking.
std::vector<std::shared_ptr<Error const>> const& errors() const { return m_errors; }
/// @returns the type of an expression and asserts that it is present.
@@ -57,6 +57,9 @@ public:
/// Adds a new error to the list of errors.
void typeError(ASTNode const& _node, std::string const& _description);
/// Adds a new warning to the list of errors.
void typeWarning(ASTNode const& _node, std::string const& _description);
/// Adds a new error to the list of errors and throws to abort type checking.
void fatalTypeError(ASTNode const& _node, std::string const& _description);