Some changes to "abstract".

This commit is contained in:
chriseth
2019-11-05 13:55:31 +01:00
parent cac2e843e6
commit 5388c919f0
20 changed files with 52 additions and 20 deletions
+16 -5
View File
@@ -134,8 +134,8 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
checkDuplicateEvents(_contract);
checkIllegalOverrides(_contract);
checkAmbiguousOverrides(_contract);
checkAbstractFunctions(_contract);
checkBaseConstructorArguments(_contract);
checkAbstractFunctions(_contract);
checkExternalTypeClashes(_contract);
checkHashCollisions(_contract);
checkLibraryRequirements(_contract);
@@ -395,6 +395,8 @@ void ContractLevelChecker::checkAbstractFunctions(ContractDefinition const& _con
}
// Set to not fully implemented if at least one flag is false.
// Note that `_contract.annotation().unimplementedFunctions` has already been
// pre-filled by `checkBaseConstructorArguments`.
for (auto const& it: functions)
for (auto const& funAndFlag: it.second)
if (!funAndFlag.second)
@@ -405,13 +407,22 @@ void ContractLevelChecker::checkAbstractFunctions(ContractDefinition const& _con
break;
}
if (_contract.abstract() && _contract.contractKind() != ContractDefinition::ContractKind::Contract)
m_errorReporter.typeError(_contract.location(), "Only contracts can be abstract.");
if (_contract.abstract())
{
if (_contract.contractKind() == ContractDefinition::ContractKind::Interface)
m_errorReporter.typeError(_contract.location(), "Interfaces do not need the \"abstract\" keyword, they are abstract implicitly.");
else if (_contract.contractKind() == ContractDefinition::ContractKind::Library)
m_errorReporter.typeError(_contract.location(), "Libraries cannot be abstract.");
else
solAssert(_contract.contractKind() == ContractDefinition::ContractKind::Contract, "");
}
// For libraries, we emit errors on function-level, so this is fine as long as we do
// not have inheritance for libraries.
if (
_contract.contractKind() == ContractDefinition::ContractKind::Contract &&
!_contract.annotation().unimplementedFunctions.empty() &&
!_contract.abstract()
!_contract.abstract() &&
!_contract.annotation().unimplementedFunctions.empty()
)
m_errorReporter.typeError(
_contract.location(),
@@ -77,6 +77,8 @@ private:
void overrideListError(FunctionDefinition const& function, std::set<ContractDefinition const*, LessFunction> _secondary, std::string const& _message1, std::string const& _message2);
void overrideError(CallableDeclaration const& function, CallableDeclaration const& super, std::string message);
void checkAbstractFunctions(ContractDefinition const& _contract);
/// Checks that the base constructor arguments are properly provided.
/// Fills the list of unimplemented functions in _contract's annotations.
void checkBaseConstructorArguments(ContractDefinition const& _contract);
void annotateBaseConstructorArguments(
ContractDefinition const& _currentContract,
+3 -3
View File
@@ -423,8 +423,8 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
_function.body().accept(*this);
else if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor must be implemented if declared.");
else if (isLibraryFunction && _function.visibility() <= FunctionDefinition::Visibility::Internal)
m_errorReporter.typeError(_function.location(), "Internal library function must be implemented if declared.");
else if (isLibraryFunction)
m_errorReporter.typeError(_function.location(), "Library functions must be implemented if declared.");
if (_function.isFallback())
@@ -2228,7 +2228,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
m_errorReporter.fatalTypeError(_newExpression.location(), "Cannot instantiate an interface.");
if (!contract->constructorIsPublic())
m_errorReporter.typeError(_newExpression.location(), "Contract with internal constructor cannot be created directly.");
if (contract->abstract() || !contract->annotation().unimplementedFunctions.empty())
if (contract->abstract())
m_errorReporter.typeError(_newExpression.location(), "Cannot instantiate an abstract contract.");
solAssert(!!m_scope, "");