From cc6314cd019be80a9212f6bd5b0c86206be16c88 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 21 Jun 2016 14:36:23 +0200 Subject: Warn about unused return values. --- libsolidity/analysis/TypeChecker.cpp | 17 +++++++++++++++++ libsolidity/analysis/TypeChecker.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index ce55de00..c2fd3e7e 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -830,6 +830,13 @@ void TypeChecker::endVisit(ExpressionStatement const& _statement) if (type(_statement.expression())->category() == Type::Category::RationalNumber) if (!dynamic_cast(*type(_statement.expression())).mobileType()) typeError(_statement.expression().location(), "Invalid rational number."); + + bool unusedReturnValue = true; + if (auto t = dynamic_cast(type(_statement.expression()).get())) + if (t->components().empty()) + unusedReturnValue = false; + if (unusedReturnValue) + warning(_statement.location(), "Unused return value."); } bool TypeChecker::visit(Conditional const& _conditional) @@ -1570,6 +1577,16 @@ void TypeChecker::typeError(SourceLocation const& _location, string const& _desc m_errors.push_back(err); } +void TypeChecker::warning(SourceLocation const& _location, string const& _description) +{ + auto err = make_shared(Error::Type::Warning); + *err << + errinfo_sourceLocation(_location) << + errinfo_comment(_description); + + m_errors.push_back(err); +} + void TypeChecker::fatalTypeError(SourceLocation const& _location, string const& _description) { typeError(_location, _description); diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 48f8285a..be1e02be 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -59,6 +59,9 @@ private: /// Adds a new error to the list of errors. void typeError(SourceLocation const& _location, std::string const& _description); + /// Adds a new warning to the list of errors. + void warning(SourceLocation const& _location, std::string const& _description); + /// Adds a new error to the list of errors and throws to abort type checking. void fatalTypeError(SourceLocation const& _location, std::string const& _description); -- cgit