mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Some changes to "abstract".
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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, "");
|
||||
|
||||
Reference in New Issue
Block a user