From b3b8441aa4514764f6ae2387f891f42c6c606127 Mon Sep 17 00:00:00 2001 From: a3d4 Date: Fri, 7 Feb 2020 02:36:51 +0100 Subject: [PATCH] Fix printing source for missing pragma. --- liblangutil/SourceReferenceExtractor.cpp | 2 +- liblangutil/SourceReferenceFormatter.cpp | 2 ++ liblangutil/SourceReferenceFormatterHuman.cpp | 9 ++++++++- libsolidity/analysis/SyntaxChecker.cpp | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/liblangutil/SourceReferenceExtractor.cpp b/liblangutil/SourceReferenceExtractor.cpp index 44f1540ca..0817e7750 100644 --- a/liblangutil/SourceReferenceExtractor.cpp +++ b/liblangutil/SourceReferenceExtractor.cpp @@ -46,7 +46,7 @@ SourceReference SourceReferenceExtractor::extract(SourceLocation const* _locatio if (!_location || !_location->source.get()) // Nothing we can extract here return SourceReference::MessageOnly(std::move(message)); - if (_location->source->source().empty()) // No source text, so we can only extract the source name + if (!_location->hasText()) // No source text, so we can only extract the source name return SourceReference::MessageOnly(std::move(message), _location->source->name()); shared_ptr const& source = _location->source; diff --git a/liblangutil/SourceReferenceFormatter.cpp b/liblangutil/SourceReferenceFormatter.cpp index 588733d27..6b1a8286a 100644 --- a/liblangutil/SourceReferenceFormatter.cpp +++ b/liblangutil/SourceReferenceFormatter.cpp @@ -69,6 +69,8 @@ void SourceReferenceFormatter::printSourceName(SourceReference const& _ref) { if (_ref.position.line != -1) m_stream << _ref.sourceName << ":" << (_ref.position.line + 1) << ":" << (_ref.position.column + 1) << ": "; + else if (!_ref.sourceName.empty()) + m_stream << _ref.sourceName << ": "; } void SourceReferenceFormatter::printExceptionInformation(util::Exception const& _exception, std::string const& _category) diff --git a/liblangutil/SourceReferenceFormatterHuman.cpp b/liblangutil/SourceReferenceFormatterHuman.cpp index 6cd5620fb..669fa2007 100644 --- a/liblangutil/SourceReferenceFormatterHuman.cpp +++ b/liblangutil/SourceReferenceFormatterHuman.cpp @@ -67,13 +67,20 @@ AnsiColorized SourceReferenceFormatterHuman::diagColored() const void SourceReferenceFormatterHuman::printSourceLocation(SourceReference const& _ref) { - if (_ref.position.line < 0) + if (_ref.sourceName.empty()) return; // Nothing we can print here int const leftpad = static_cast(log10(max(_ref.position.line, 1))) + 1; // line 0: source name frameColored() << string(leftpad, ' ') << "--> "; + + if (_ref.position.line < 0) + { + m_stream << _ref.sourceName << "\n"; + return; // No line available, nothing else to print + } + m_stream << _ref.sourceName << ":" << (_ref.position.line + 1) << ":" << (_ref.position.column + 1) << ":" << '\n'; if (!_ref.multiline) diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 666c15dc5..74fa8d458 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -68,7 +68,8 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit) to_string(recommendedVersion.patch()) + string(";\""); - m_errorReporter.warning(_sourceUnit.location(), errorString); + // when reporting the warning, print the source name only + m_errorReporter.warning({-1, -1, _sourceUnit.location().source}, errorString); } m_sourceUnit = nullptr; }