Make visibility optional, but it has to be consistent.

This commit is contained in:
chriseth
2020-07-07 12:16:18 +02:00
parent 479d7a059f
commit 5959d442cb
13 changed files with 78 additions and 15 deletions
+1 -7
View File
@@ -301,13 +301,7 @@ bool SyntaxChecker::visit(ContractDefinition const& _contract)
bool SyntaxChecker::visit(FunctionDefinition const& _function)
{
if (_function.isConstructor() && !_function.noVisibilitySpecified())
m_errorReporter.syntaxError(
2462_error,
_function.location(),
"Visibility specified for constructor. If you want the contract to be non-deployable, make it \"abstract\"."
);
else if (!_function.isConstructor() && _function.noVisibilitySpecified())
if (!_function.isConstructor() && _function.noVisibilitySpecified())
{
string suggestedVisibility = _function.isFallback() || _function.isReceive() || m_isInterface ? "external" : "public";
m_errorReporter.syntaxError(
+24
View File
@@ -1922,6 +1922,30 @@ void TypeChecker::typeCheckConstructor(FunctionDefinition const& _function)
stateMutabilityToString(_function.stateMutability()) +
"\"."
);
if (!_function.noVisibilitySpecified())
{
auto const& contract = dynamic_cast<ContractDefinition const&>(*_function.scope());
if (_function.visibility() != Visibility::Public && _function.visibility() != Visibility::Internal)
m_errorReporter.typeError(9239_error, _function.location(), "Constructor cannot have visibility.");
else if (_function.isPublic() && contract.abstract())
m_errorReporter.declarationError(
8295_error,
_function.location(),
"Abstract contracts cannot have public constructors. Remove the \"public\" keyword to fix this."
);
else if (!_function.isPublic() && !contract.abstract())
m_errorReporter.declarationError(
1845_error,
_function.location(),
"Non-abstract contracts cannot have internal constructors. Remove the \"internal\" keyword and make the contract abstract to fix this."
);
else
m_errorReporter.warning(
2462_error,
_function.location(),
"Visibility for constructor is ignored. If you want the contract to be non-deployable, making it \"abstract\" is sufficient."
);
}
}
void TypeChecker::typeCheckABIEncodeFunctions(