Add error IDs to OverrideChecker

This commit is contained in:
a3d4 2020-05-12 02:26:02 +02:00
parent 3fbde6e782
commit 1d5350e32f
2 changed files with 25 additions and 14 deletions

View File

@ -506,12 +506,13 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
);
if (!_overriding.overrides())
overrideError(_overriding, _super, "Overriding " + _overriding.astNodeName() + " is missing \"override\" specifier.");
overrideError(_overriding, _super, 9456_error, "Overriding " + _overriding.astNodeName() + " is missing \"override\" specifier.");
if (_super.isVariable())
overrideError(
_super,
_overriding,
1452_error,
"Cannot override public state variable.",
"Overriding " + _overriding.astNodeName() + " is here:"
);
@ -519,6 +520,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
overrideError(
_super,
_overriding,
4334_error,
"Trying to override non-virtual " + _super.astNodeName() + ". Did you forget to add \"virtual\"?",
"Overriding " + _overriding.astNodeName() + " is here:"
);
@ -526,7 +528,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
if (_overriding.isVariable())
{
if (_super.visibility() != Visibility::External)
overrideError(_overriding, _super, "Public state variables can only override functions with external visibility.");
overrideError(_overriding, _super, 5225_error, "Public state variables can only override functions with external visibility.");
solAssert(_overriding.visibility() == Visibility::External, "");
}
else if (_overriding.visibility() != _super.visibility())
@ -537,7 +539,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
_super.visibility() == Visibility::External &&
_overriding.visibility() == Visibility::Public
))
overrideError(_overriding, _super, "Overriding " + _overriding.astNodeName() + " visibility differs.");
overrideError(_overriding, _super, 9098_error, "Overriding " + _overriding.astNodeName() + " visibility differs.");
}
if (_super.isFunction())
@ -548,7 +550,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
solAssert(functionType->hasEqualParameterTypes(*superType), "Override doesn't have equal parameters!");
if (!functionType->hasEqualReturnTypes(*superType))
overrideError(_overriding, _super, "Overriding " + _overriding.astNodeName() + " return types differ.");
overrideError(_overriding, _super, 4822_error, "Overriding " + _overriding.astNodeName() + " return types differ.");
// This is only relevant for a function overriding a function.
if (_overriding.isFunction())
@ -557,6 +559,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
overrideError(
_overriding,
_super,
2837_error,
"Overriding function changes state mutability from \"" +
stateMutabilityToString(_super.stateMutability()) +
"\" to \"" +
@ -568,6 +571,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
overrideError(
_overriding,
_super,
4593_error,
"Overriding an implemented function with an unimplemented function is not allowed."
);
}
@ -577,6 +581,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
void OverrideChecker::overrideListError(
OverrideProxy const& _item,
set<ContractDefinition const*, CompareByID> _secondary,
ErrorId _error,
string const& _message1,
string const& _message2
)
@ -594,7 +599,7 @@ void OverrideChecker::overrideListError(
contractSingularPlural = "contracts ";
m_errorReporter.typeError(
5883_error,
_error,
_item.overrides() ? _item.overrides()->location() : _item.location(),
ssl,
_message1 +
@ -605,10 +610,10 @@ void OverrideChecker::overrideListError(
);
}
void OverrideChecker::overrideError(Declaration const& _overriding, Declaration const& _super, string const& _message, string const& _secondaryMsg)
void OverrideChecker::overrideError(Declaration const& _overriding, Declaration const& _super, ErrorId _error, string const& _message, string const& _secondaryMsg)
{
m_errorReporter.typeError(
9456_error,
_error,
_overriding.location(),
SecondarySourceLocation().append(_secondaryMsg, _super.location()),
_message
@ -616,10 +621,10 @@ void OverrideChecker::overrideError(Declaration const& _overriding, Declaration
}
void OverrideChecker::overrideError(OverrideProxy const& _overriding, OverrideProxy const& _super, string const& _message, string const& _secondaryMsg)
void OverrideChecker::overrideError(OverrideProxy const& _overriding, OverrideProxy const& _super, ErrorId _error, string const& _message, string const& _secondaryMsg)
{
m_errorReporter.typeError(
1452_error,
_error,
_overriding.location(),
SecondarySourceLocation().append(_secondaryMsg, _super.location()),
_message
@ -773,11 +778,11 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
4520_error,
list[i]->location(),
ssl,
"Duplicate contract \"" +
joinHumanReadable(list[i]->namePath(), ".") +
"\" found in override list of \"" +
_item.name() +
"\"."
"Duplicate contract \"" +
joinHumanReadable(list[i]->namePath(), ".") +
"\" found in override list of \"" +
_item.name() +
"\"."
);
}
}
@ -810,6 +815,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
overrideListError(
_item,
missingContracts,
4327_error,
_item.astNodeNameCapitalized() + " needs to specify overridden ",
""
);
@ -819,6 +825,7 @@ void OverrideChecker::checkOverrideList(OverrideProxy _item, OverrideProxyBySign
overrideListError(
_item,
surplusContracts,
2353_error,
"Invalid ",
"specified in override list: "
);

View File

@ -32,6 +32,7 @@
namespace solidity::langutil
{
class ErrorReporter;
struct ErrorId;
struct SourceLocation;
}
@ -160,18 +161,21 @@ private:
void overrideListError(
OverrideProxy const& _item,
std::set<ContractDefinition const*, CompareByID> _secondary,
langutil::ErrorId _error,
std::string const& _message1,
std::string const& _message2
);
void overrideError(
Declaration const& _overriding,
Declaration const& _super,
langutil::ErrorId _error,
std::string const& _message,
std::string const& _secondaryMsg = "Overridden function is here:"
);
void overrideError(
OverrideProxy const& _overriding,
OverrideProxy const& _super,
langutil::ErrorId _error,
std::string const& _message,
std::string const& _secondaryMsg = "Overridden function is here:"
);