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/analysis/TypeChecker.cpp | |
parent | d968912a4ce89a40d7d03bf0748a07c397662f68 (diff) | |
download | dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.gz dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.bz2 dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.lz dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.xz dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.tar.zst dexon-solidity-a5ceaac8df80f89112bb4d7bbfd9da165d370aa3.zip |
Improve override changes signature error message
Diffstat (limited to 'libsolidity/analysis/TypeChecker.cpp')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 32 |
1 files changed, 31 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); +} |