Skip to content

Commit

Permalink
Use a secondary location for function override errors
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond authored and axic committed Aug 11, 2017
1 parent a694985 commit d4997dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
39 changes: 15 additions & 24 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,40 +306,31 @@ void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, Func
return;

if (function.visibility() != super.visibility())
m_errorReporter.typeError(
function.location(),
"Overriding function visibility differs from " + super.fullyQualifiedName() + "."
);
overrideError(function, super, "Overriding function visibility differs.");

if (function.isDeclaredConst() && !super.isDeclaredConst())
m_errorReporter.typeError(
function.location(),
"Overriding function should not be declared constant."
);
overrideError(function, super, "Overriding function should not be declared constant.");

if (!function.isDeclaredConst() && super.isDeclaredConst())
m_errorReporter.typeError(
function.location(),
"Overriding function should be declared constant."
);
overrideError(function, super, "Overriding function should be declared constant.");

if (function.isPayable() && !super.isPayable())
m_errorReporter.typeError(
function.location(),
"Overriding function should not be declared payable."
);
overrideError(function, super, "Overriding function should not be declared payable.");

if (!function.isPayable() && super.isPayable())
m_errorReporter.typeError(
function.location(),
"Overriding function should be declared payable."
);
overrideError(function, super, "Overriding function should be declared payable.");

if (functionType != superType)
m_errorReporter.typeError(
function.location(),
"Overriding function return types differ from " + super.fullyQualifiedName() + "."
);
overrideError(function, super, "Overriding function return types differ.");
}

void TypeChecker::overrideError(FunctionDefinition const& function, FunctionDefinition const& super, string message)
{
m_errorReporter.typeError(
function.location(),
SecondarySourceLocation().append("Overriden function is here:", super.location()),
message
);
}

void TypeChecker::checkContractExternalTypeClashes(ContractDefinition const& _contract)
Expand Down
1 change: 1 addition & 0 deletions libsolidity/analysis/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TypeChecker: private ASTConstVisitor
void checkContractIllegalOverrides(ContractDefinition const& _contract);
/// Reports a type error with an appropiate message if overriden function signature differs.
void checkFunctionOverride(FunctionDefinition const& function, FunctionDefinition const& super);
void overrideError(FunctionDefinition const& function, FunctionDefinition const& super, std::string message);
void checkContractAbstractFunctions(ContractDefinition const& _contract);
void checkContractAbstractConstructors(ContractDefinition const& _contract);
/// Checks that different functions with external visibility end up having different
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/interface/ErrorReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ErrorReporter

void typeError(
SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation,
std::string const& _description
SecondarySourceLocation const& _secondaryLocation = SecondarySourceLocation(),
std::string const& _description = std::string()
);

void typeError(SourceLocation const& _location, std::string const& _description);
Expand Down

0 comments on commit d4997dd

Please sign in to comment.