mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
@@ -580,9 +580,6 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
|
||||
|
||||
bool TypeChecker::visit(StructDefinition const& _struct)
|
||||
{
|
||||
if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface)
|
||||
m_errorReporter.typeError(_struct.location(), "Structs cannot be defined in interfaces.");
|
||||
|
||||
for (ASTPointer<VariableDeclaration> const& member: _struct.members())
|
||||
if (!type(*member)->canBeStored())
|
||||
m_errorReporter.typeError(member->location(), "Type cannot be used in struct.");
|
||||
@@ -610,7 +607,10 @@ bool TypeChecker::visit(StructDefinition const& _struct)
|
||||
if (CycleDetector<StructDefinition>(visitor).run(_struct) != nullptr)
|
||||
m_errorReporter.fatalTypeError(_struct.location(), "Recursive struct definition.");
|
||||
|
||||
bool insideStruct = true;
|
||||
swap(insideStruct, m_insideStruct);
|
||||
ASTNode::listAccept(_struct.members(), *this);
|
||||
m_insideStruct = insideStruct;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -693,10 +693,12 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
||||
bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
{
|
||||
// Forbid any variable declarations inside interfaces unless they are part of
|
||||
// a function's input/output parameters.
|
||||
// * a function's input/output parameters,
|
||||
// * or inside of a struct definition.
|
||||
if (
|
||||
m_scope->contractKind() == ContractDefinition::ContractKind::Interface
|
||||
&& !_variable.isCallableParameter()
|
||||
&& !m_insideStruct
|
||||
)
|
||||
m_errorReporter.typeError(_variable.location(), "Variables cannot be declared in interfaces.");
|
||||
|
||||
|
||||
@@ -149,6 +149,9 @@ private:
|
||||
/// Flag indicating whether we are currently inside an EmitStatement.
|
||||
bool m_insideEmitStatement = false;
|
||||
|
||||
/// Flag indicating whether we are currently inside a StructDefinition.
|
||||
bool m_insideStruct = false;
|
||||
|
||||
ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user