aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/AST.cpp b/AST.cpp
index d05eaf83..1736469e 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -88,7 +88,7 @@ void ContractDefinition::checkTypeRequirements()
if (hashes.count(hash))
BOOST_THROW_EXCEPTION(createTypeError(
std::string("Function signature hash collision for ") +
- it.second->getCanonicalSignature()));
+ it.second->externalSignature()));
hashes.insert(hash);
}
}
@@ -192,7 +192,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface())
{
functionsSeen.insert(f->getName());
- FixedHash<4> hash(dev::sha3(f->getCanonicalSignature()));
+ FixedHash<4> hash(dev::sha3(f->externalSignature()));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false)));
}
@@ -200,8 +200,9 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(v->getName()) == 0 && v->isPartOfExternalInterface())
{
FunctionType ftype(*v);
+ solAssert(v->getType().get(), "");
functionsSeen.insert(v->getName());
- FixedHash<4> hash(dev::sha3(ftype.getCanonicalSignature(v->getName())));
+ FixedHash<4> hash(dev::sha3(ftype.externalSignature(v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
}
}
@@ -305,8 +306,12 @@ TypePointer FunctionDefinition::getType(ContractDefinition const*) const
void FunctionDefinition::checkTypeRequirements()
{
for (ASTPointer<VariableDeclaration> const& var: getParameters() + getReturnParameters())
+ {
if (!var->getType()->canLiveOutsideStorage())
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 function with external visibility"));
+ }
for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers)
modifier->checkTypeRequirements(isConstructor() ?
dynamic_cast<ContractDefinition const&>(*getScope()).getBaseContracts() :
@@ -315,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements();
}
-string FunctionDefinition::getCanonicalSignature() const
+string FunctionDefinition::externalSignature() const
{
- return FunctionType(*this).getCanonicalSignature(getName());
+ return FunctionType(*this).externalSignature(getName());
}
bool VariableDeclaration::isLValue() const
@@ -342,8 +347,11 @@ void VariableDeclaration::checkTypeRequirements()
if (!m_value)
return;
if (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
m_value->checkTypeRequirements();
@@ -422,6 +430,8 @@ void EventDefinition::checkTypeRequirements()
numIndexed++;
if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
+ if (!var->getType()->externalType())
+ BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed as event parameter type."));
}
if (numIndexed > 3)
BOOST_THROW_EXCEPTION(createTypeError("More than 3 indexed arguments for event."));