Browse Source

added check for events and stat variables

cl-refactor
Liana Husikyan 10 years ago
parent
commit
44c7da4262
  1. 13
      libsolidity/AST.cpp
  2. 8
      libsolidity/Types.cpp
  3. 3
      libsolidity/Types.h

13
libsolidity/AST.cpp

@ -346,8 +346,11 @@ void VariableDeclaration::checkTypeRequirements()
if (!m_value) if (!m_value)
return; return;
if (m_type) if (m_type)
{
m_value->expectType(*m_type); m_value->expectType(*m_type);
else if (m_isStateVariable && !m_type->externalType() && getVisibility() >= Visibility::Public)
BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for state variables."));
} else
{ {
// no type declared and no previous assignment, infer the type // no type declared and no previous assignment, infer the type
m_value->checkTypeRequirements(); m_value->checkTypeRequirements();
@ -426,6 +429,8 @@ void EventDefinition::checkTypeRequirements()
numIndexed++; numIndexed++;
if (!var->getType()->canLiveOutsideStorage()) if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage.")); BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
if (!var->getType()->externalType() && getVisibility() >= Visibility::Public)
BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for Events"));
} }
if (numIndexed > 3) if (numIndexed > 3)
BOOST_THROW_EXCEPTION(createTypeError("More than 3 indexed arguments for event.")); BOOST_THROW_EXCEPTION(createTypeError("More than 3 indexed arguments for event."));
@ -657,9 +662,9 @@ void MemberAccess::checkTypeRequirements()
if (!m_type) if (!m_type)
BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found or not " BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found or not "
"visible in " + type.toString())); "visible in " + type.toString()));
//todo check for visibility // if (auto f = dynamic_cast<FunctionType const*>(m_expression->getType().get()))
// else if (!m_type->externalType()) // if (f->getLocation() == FunctionType::Location::External && !m_type->externalType())
// BOOST_THROW_EXCEPTION(createTypeError("Internal type not allowed for function with external visibility")); // BOOST_THROW_EXCEPTION(createTypeError(*m_memberName + " member has an internal type."));
// This should probably move somewhere else. // This should probably move somewhere else.
if (type.getCategory() == Type::Category::Struct) if (type.getCategory() == Type::Category::Struct)

8
libsolidity/Types.cpp

@ -748,14 +748,12 @@ TypePointer ArrayType::externalType() const
return TypePointer(); return TypePointer();
if (m_isByteArray) if (m_isByteArray)
return shared_from_this(); return shared_from_this();
if (!(m_baseType->externalType())) if (!m_baseType->externalType())
{
return TypePointer(); return TypePointer();
} if (m_baseType->getCategory() == Category::Array && m_baseType->isDynamicallySized())
if (dynamic_cast<ArrayType const*>(m_baseType.get()) && m_baseType->isDynamicallySized())
return TypePointer(); return TypePointer();
if (m_baseType->isDynamicallySized()) if (isDynamicallySized())
return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType()); return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType());
else else
return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType(), m_length); return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType(), m_length);

3
libsolidity/Types.h

@ -187,7 +187,8 @@ public:
"for type without literals.")); "for type without literals."));
} }
/// Returns address of type for ABI interface /// @returns a type suitable for outside of Solidity, i.e. for contract types it returns address.
/// If there is no such type, returns an empty shared pointer.
virtual TypePointer externalType() const { return TypePointer(); } virtual TypePointer externalType() const { return TypePointer(); }
protected: protected:

Loading…
Cancel
Save