Merge pull request #1737 from ethereum/localmappings

Disallow uninitialized mapping variables.
This commit is contained in:
chriseth
2017-03-06 15:05:58 +01:00
committed by GitHub
4 changed files with 41 additions and 4 deletions
+5 -2
View File
@@ -730,13 +730,16 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
if (auto ref = dynamic_cast<ReferenceType const*>(type(varDecl).get()))
{
if (ref->dataStoredIn(DataLocation::Storage))
{
warning(
varDecl.location(),
"Uninitialized storage pointer. Did you mean '<type> memory " + varDecl.name() + "'?"
);
}
}
else if (dynamic_cast<MappingType const*>(type(varDecl).get()))
typeError(
varDecl.location(),
"Uninitialized mapping. Mappings cannot be created dynamically, you have to assign them from a state variable."
);
varDecl.accept(*this);
return false;
}
+7 -1
View File
@@ -27,7 +27,8 @@ using namespace std;
using namespace dev;
using namespace dev::solidity;
Error::Error(Type _type): m_type(_type)
Error::Error(Type _type, SourceLocation const& _location, string const& _description):
m_type(_type)
{
switch(m_type)
{
@@ -56,6 +57,11 @@ Error::Error(Type _type): m_type(_type)
solAssert(false, "");
break;
}
if (!_location.isEmpty())
*this << errinfo_sourceLocation(_location);
if (!_description.empty())
*this << errinfo_comment(_description);
}
string Exception::lineInfo() const
+5 -1
View File
@@ -53,7 +53,11 @@ public:
Warning
};
explicit Error(Type _type);
explicit Error(
Type _type,
SourceLocation const& _location = SourceLocation(),
std::string const& _description = std::string()
);
Type type() const { return m_type; }
std::string const& typeName() const { return m_typeName; }