Skip to content

Commit 51009c0

Browse files
committed
Moved a canBeStored assert for struct members to TypeChecker
This is to avoid a assert from failing for forward declared user defined value types.
1 parent 9428dbc commit 51009c0

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

libsolidity/analysis/DeclarationTypeChecker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ bool DeclarationTypeChecker::visit(StructDefinition const& _struct)
100100
m_recursiveStructSeen = false;
101101
member->accept(*this);
102102
solAssert(member->annotation().type, "");
103-
solAssert(member->annotation().type->canBeStored(), "Type cannot be used in struct.");
104103
if (m_recursiveStructSeen)
105104
hasRecursiveChild = true;
106105
}

libsolidity/analysis/TypeChecker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,16 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
621621
return false;
622622
}
623623

624+
void TypeChecker::endVisit(StructDefinition const& _struct)
625+
{
626+
for (auto const& member: _struct.members())
627+
solAssert(
628+
member->annotation().type &&
629+
member->annotation().type->canBeStored(),
630+
"Type cannot be used in struct."
631+
);
632+
}
633+
624634
void TypeChecker::visitManually(
625635
ModifierInvocation const& _modifier,
626636
vector<ContractDefinition const*> const& _bases

libsolidity/analysis/TypeChecker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class TypeChecker: private ASTConstVisitor
121121
bool visit(FunctionDefinition const& _function) override;
122122
void endVisit(ArrayTypeName const& _typeName) override;
123123
bool visit(VariableDeclaration const& _variable) override;
124+
void endVisit(StructDefinition const& _struct) override;
124125
/// We need to do this manually because we want to pass the bases of the current contract in
125126
/// case this is a base constructor call.
126127
void visitManually(ModifierInvocation const& _modifier, std::vector<ContractDefinition const*> const& _bases);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct S { U u; }
2+
contract C { S s; }
3+
type U is address;

0 commit comments

Comments
 (0)