Warn about unused return values.

This commit is contained in:
chriseth
2016-06-26 13:53:32 +02:00
parent 460ed095f8
commit cc6314cd01
3 changed files with 45 additions and 0 deletions
+17
View File
@@ -830,6 +830,13 @@ void TypeChecker::endVisit(ExpressionStatement const& _statement)
if (type(_statement.expression())->category() == Type::Category::RationalNumber)
if (!dynamic_cast<RationalNumberType const&>(*type(_statement.expression())).mobileType())
typeError(_statement.expression().location(), "Invalid rational number.");
bool unusedReturnValue = true;
if (auto t = dynamic_cast<TupleType const*>(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>(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);
+3
View File
@@ -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);