Moved a canBeStored assert for struct members to TypeChecker

This is to avoid a assert from failing for forward declared user defined value types.
This commit is contained in:
hrkrshnn 2021-10-26 18:31:13 +02:00
parent 9428dbc94f
commit 51009c005d
4 changed files with 14 additions and 1 deletions

View File

@ -100,7 +100,6 @@ bool DeclarationTypeChecker::visit(StructDefinition const& _struct)
m_recursiveStructSeen = false;
member->accept(*this);
solAssert(member->annotation().type, "");
solAssert(member->annotation().type->canBeStored(), "Type cannot be used in struct.");
if (m_recursiveStructSeen)
hasRecursiveChild = true;
}

View File

@ -621,6 +621,16 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
return false;
}
void TypeChecker::endVisit(StructDefinition const& _struct)
{
for (auto const& member: _struct.members())
solAssert(
member->annotation().type &&
member->annotation().type->canBeStored(),
"Type cannot be used in struct."
);
}
void TypeChecker::visitManually(
ModifierInvocation const& _modifier,
vector<ContractDefinition const*> const& _bases

View File

@ -121,6 +121,7 @@ private:
bool visit(FunctionDefinition const& _function) override;
void endVisit(ArrayTypeName const& _typeName) override;
bool visit(VariableDeclaration const& _variable) override;
void endVisit(StructDefinition const& _struct) override;
/// We need to do this manually because we want to pass the bases of the current contract in
/// case this is a base constructor call.
void visitManually(ModifierInvocation const& _modifier, std::vector<ContractDefinition const*> const& _bases);

View File

@ -0,0 +1,3 @@
struct S { U u; }
contract C { S s; }
type U is address;