Improve override changes signature error message

This commit is contained in:
Federico Bond 2017-07-17 16:47:44 -03:00 committed by Alex Beregszaszi
parent d968912a4c
commit a5ceaac8df
3 changed files with 35 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Features:
* Parser: Display previous visibility specifier in error if multiple are found.
* Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
* Metadata: Store experimental flag in metadata CBOR.
* Type Checker: More detailed error message for invalid overrides.
Bugfixes:
* Parser: Enforce commas between array and tuple elements.

View File

@ -290,7 +290,7 @@ void TypeChecker::checkContractIllegalOverrides(ContractDefinition const& _contr
overriding->isPayable() != function->isPayable() ||
overridingType != functionType
)
m_errorReporter.typeError(overriding->location(), "Override changes extended function signature.");
overrideTypeError(*overriding, *function);
}
functions[name].push_back(function);
}
@ -1950,3 +1950,33 @@ void TypeChecker::requireLValue(Expression const& _expression)
m_errorReporter.typeError(_expression.location(), "Expression has to be an lvalue.");
}
void TypeChecker::overrideTypeError(FunctionDefinition const& function, FunctionDefinition const& super)
{
string message;
if (function.visibility() != super.visibility())
message = "Overriding function visibility differs from extended function.";
else if (function.isDeclaredConst() && !super.isDeclaredConst())
message = "Overriding function should not be declared constant.";
else if (!function.isDeclaredConst() && super.isDeclaredConst())
message = "Overriding function should be declared constant.";
else if (function.isPayable() && !super.isPayable())
message = "Overriding function should not be declared payable.";
else if (!function.isPayable() && super.isPayable())
message = "Overriding function should be declared payable.";
if (message.empty())
{
FunctionType functionType(function);
FunctionType superType(super);
if (functionType != superType)
message = "Overriding function return types differ from extended function.";
}
if (message.empty())
message = "Override changes extended function signature.";
m_errorReporter.typeError(function.location(), message);
}

View File

@ -120,6 +120,9 @@ private:
/// Runs type checks on @a _expression to infer its type and then checks that it is an LValue.
void requireLValue(Expression const& _expression);
/// Reports a type error with an appropiate message when overriden function signature differs.
void overrideTypeError(FunctionDefinition const& function, FunctionDefinition const& super);
ContractDefinition const* m_scope = nullptr;
ErrorReporter& m_errorReporter;