Use fully qualified name of super in message

This commit is contained in:
Federico Bond 2017-07-17 19:12:34 -03:00 committed by Alex Beregszaszi
parent a5ceaac8df
commit ff5bb54e3c
3 changed files with 13 additions and 4 deletions

View File

@ -1950,13 +1950,12 @@ 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.";
message = "Overriding function visibility differs from " + super.fullyQualifiedName() + ".";
else if (function.isDeclaredConst() && !super.isDeclaredConst())
message = "Overriding function should not be declared constant.";
else if (!function.isDeclaredConst() && super.isDeclaredConst())
@ -1972,11 +1971,11 @@ void TypeChecker::overrideTypeError(FunctionDefinition const& function, Function
FunctionType superType(super);
if (functionType != superType)
message = "Overriding function return types differ from extended function.";
message = "Overriding function return types differ from " + super.fullyQualifiedName() + ".";
}
if (message.empty())
message = "Override changes extended function signature.";
message = "Overriding function signature differs from " + super.fullyQualifiedName() + ".";
m_errorReporter.typeError(function.location(), message);
}

View File

@ -371,6 +371,15 @@ string FunctionDefinition::externalSignature() const
return FunctionType(*this).externalSignature();
}
string FunctionDefinition::fullyQualifiedName() const
{
auto const* contract = dynamic_cast<ContractDefinition const*>(scope());
solAssert(contract, "Enclosing scope of function definition was not set.");
auto fname = name().empty() ? "<fallback>" : name();
return sourceUnitName() + ":" + contract->name() + "." + fname;
}
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
{
if (!m_annotation)

View File

@ -613,6 +613,7 @@ public:
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
Block const& body() const { solAssert(m_body, ""); return *m_body; }
std::string fullyQualifiedName() const;
virtual bool isVisibleInContract() const override
{
return Declaration::isVisibleInContract() && !isConstructor() && !isFallback();