Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth
2021-10-27 18:09:13 +02:00
280 changed files with 2237 additions and 239 deletions
+10 -10
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;
}
@@ -289,7 +288,6 @@ void DeclarationTypeChecker::endVisit(ArrayTypeName const& _typeName)
return;
}
solAssert(baseType->storageBytes() != 0, "Illegal base type of storage size zero for array.");
if (Expression const* length = _typeName.length())
{
optional<rational> lengthValue;
@@ -439,14 +437,16 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
type = TypeProvider::withLocation(ref, typeLoc, isPointer);
}
if (_variable.isConstant() && !type->isValueType())
{
bool allowed = false;
if (auto arrayType = dynamic_cast<ArrayType const*>(type))
allowed = arrayType->isByteArray();
if (!allowed)
m_errorReporter.fatalDeclarationError(9259_error, _variable.location(), "Constants of non-value type not yet implemented.");
}
if (
_variable.isConstant() &&
!dynamic_cast<UserDefinedValueType const*>(type) &&
type->containsNestedMapping()
)
m_errorReporter.fatalDeclarationError(
3530_error,
_variable.location(),
"The type contains a (nested) mapping and therefore cannot be a constant."
);
_variable.annotation().type = type;
}
+27
View File
@@ -530,6 +530,15 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
}
if (_variable.isConstant())
{
if (!varType->isValueType())
{
bool allowed = false;
if (auto arrayType = dynamic_cast<ArrayType const*>(varType))
allowed = arrayType->isByteArray();
if (!allowed)
m_errorReporter.fatalTypeError(9259_error, _variable.location(), "Constants of non-value type not yet implemented.");
}
if (!_variable.value())
m_errorReporter.typeError(4266_error, _variable.location(), "Uninitialized \"constant\" variable.");
else if (!*_variable.value()->annotation().isPure)
@@ -621,6 +630,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
@@ -1213,6 +1232,14 @@ void TypeChecker::endVisit(RevertStatement const& _revert)
m_errorReporter.typeError(1885_error, errorCall.expression().location(), "Expression has to be an error.");
}
void TypeChecker::endVisit(ArrayTypeName const& _typeName)
{
solAssert(
_typeName.baseType().annotation().type &&
_typeName.baseType().annotation().type->storageBytes() != 0,
"Illegal base type of storage size zero for array."
);
}
bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
{
+2
View File
@@ -119,7 +119,9 @@ private:
void endVisit(InheritanceSpecifier const& _inheritance) override;
void endVisit(ModifierDefinition const& _modifier) override;
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);