diff options
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 32 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 3 |
3 files changed, 35 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index 4609da92..b4ca745f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 6852c13d..a7433250 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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); +} diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index ee43d13a..17dde81a 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -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; |