mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
libutil: Fix Pos::getSourcePath
Previous implementation didn't actually check if std::get_if returned a nullptr: std::optional<SourcePath> getSourcePath() const { return *std::get_if<SourcePath>(&origin); }
This commit is contained in:
parent
bf12aedf2e
commit
50123f2a56
2 changed files with 8 additions and 3 deletions
|
@ -66,6 +66,13 @@ std::optional<std::string> Pos::getSource() const
|
||||||
}, origin);
|
}, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<SourcePath> Pos::getSourcePath() const
|
||||||
|
{
|
||||||
|
if (auto * path = std::get_if<SourcePath>(&origin))
|
||||||
|
return *path;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void Pos::print(std::ostream & out, bool showOrigin) const
|
void Pos::print(std::ostream & out, bool showOrigin) const
|
||||||
{
|
{
|
||||||
if (showOrigin) {
|
if (showOrigin) {
|
||||||
|
|
|
@ -70,9 +70,7 @@ struct Pos
|
||||||
/**
|
/**
|
||||||
* Get the SourcePath, if the source was loaded from a file.
|
* Get the SourcePath, if the source was loaded from a file.
|
||||||
*/
|
*/
|
||||||
std::optional<SourcePath> getSourcePath() const {
|
std::optional<SourcePath> getSourcePath() const;
|
||||||
return *std::get_if<SourcePath>(&origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct LinesIterator {
|
struct LinesIterator {
|
||||||
using difference_type = size_t;
|
using difference_type = size_t;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue