Skip to content

Commit 06c87cf

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 81b063a commit 06c87cf

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
@@ -630,6 +630,16 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
630630
return false;
631631
}
632632

633+
void TypeChecker::endVisit(StructDefinition const& _struct)
634+
{
635+
for (auto const& member: _struct.members())
636+
solAssert(
637+
member->annotation().type &&
638+
member->annotation().type->canBeStored(),
639+
"Type cannot be used in struct."
640+
);
641+
}
642+
633643
void TypeChecker::visitManually(
634644
ModifierInvocation const& _modifier,
635645
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)