From 03c70f45d6d0e30d8550d485d2dd564a21b533d5 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 9 Jan 2020 14:18:54 +0100 Subject: [PATCH] Handle empty source strings in SourceReferenceExtractor --- liblangutil/SourceReferenceExtractor.cpp | 3 +++ liblangutil/SourceReferenceExtractor.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/liblangutil/SourceReferenceExtractor.cpp b/liblangutil/SourceReferenceExtractor.cpp index ff045a198..44f1540ca 100644 --- a/liblangutil/SourceReferenceExtractor.cpp +++ b/liblangutil/SourceReferenceExtractor.cpp @@ -46,6 +46,9 @@ 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 + return SourceReference::MessageOnly(std::move(message), _location->source->name()); + shared_ptr const& source = _location->source; LineColumn const interest = source->translatePositionToLineColumn(_location->start); diff --git a/liblangutil/SourceReferenceExtractor.h b/liblangutil/SourceReferenceExtractor.h index 12f608409..6aa0ab34a 100644 --- a/liblangutil/SourceReferenceExtractor.h +++ b/liblangutil/SourceReferenceExtractor.h @@ -49,10 +49,11 @@ struct SourceReference int endColumn = {-1}; ///< Highlighting range-end of text field. /// Constructs a SourceReference containing a message only. - static SourceReference MessageOnly(std::string _msg) + static SourceReference MessageOnly(std::string _msg, std::string _sourceName = {}) { SourceReference sref; sref.message = std::move(_msg); + sref.sourceName = std::move(_sourceName); return sref; } };