diff options
author | Federico Bond <federicobond@gmail.com> | 2017-07-18 03:47:44 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-12 05:45:25 +0800 |
commit | a5ceaac8df80f89112bb4d7bbfd9da165d370aa3 (patch) | |
tree | 54f1678bf4584c32ffead239dd13170ecdea03ee /libsolidity | |
parent | d968912a4ce89a40d7d03bf0748a07c397662f68 (diff) | |
download | dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.gz dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.zst dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.zip |
Improve override changes signature error message
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 32 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 3 |
2 files changed, 34 insertions, 1 deletions
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; |