mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve override changes signature error message
This commit is contained in:
parent
d968912a4c
commit
a5ceaac8df
@ -4,6 +4,7 @@ Features:
|
|||||||
* Parser: Display previous visibility specifier in error if multiple are found.
|
* Parser: Display previous visibility specifier in error if multiple are found.
|
||||||
* Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
|
* Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
|
||||||
* Metadata: Store experimental flag in metadata CBOR.
|
* Metadata: Store experimental flag in metadata CBOR.
|
||||||
|
* Type Checker: More detailed error message for invalid overrides.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Parser: Enforce commas between array and tuple elements.
|
* Parser: Enforce commas between array and tuple elements.
|
||||||
|
@ -290,7 +290,7 @@ void TypeChecker::checkContractIllegalOverrides(ContractDefinition const& _contr
|
|||||||
overriding->isPayable() != function->isPayable() ||
|
overriding->isPayable() != function->isPayable() ||
|
||||||
overridingType != functionType
|
overridingType != functionType
|
||||||
)
|
)
|
||||||
m_errorReporter.typeError(overriding->location(), "Override changes extended function signature.");
|
overrideTypeError(*overriding, *function);
|
||||||
}
|
}
|
||||||
functions[name].push_back(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.");
|
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);
|
||||||
|
}
|
||||||
|
@ -120,6 +120,9 @@ private:
|
|||||||
/// Runs type checks on @a _expression to infer its type and then checks that it is an LValue.
|
/// Runs type checks on @a _expression to infer its type and then checks that it is an LValue.
|
||||||
void requireLValue(Expression const& _expression);
|
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;
|
ContractDefinition const* m_scope = nullptr;
|
||||||
|
|
||||||
ErrorReporter& m_errorReporter;
|
ErrorReporter& m_errorReporter;
|
||||||
|
Loading…
Reference in New Issue
Block a user