Skip to content

Commit 58ae184

Browse files
committed
fix prettyPrint() crash
Fixes an edge case when the error happens on the first character of the next line
1 parent 60c9a83 commit 58ae184

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/rift/errors/compile.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ namespace rift {
4747
while (lineEnd > m_endIndex && m_source[lineEnd] == ' ') {
4848
lineEnd--;
4949
}
50-
51-
return fmt::format("{}\n{}\n{:>{}}", m_message, m_source.substr(lineStart, lineEnd - lineStart), std::string(length, '^'), m_index - lineStart);
50+
return fmt::format(
51+
"{}\n{}\n{:>{}}",
52+
m_message,
53+
m_source.substr(lineStart, lineEnd - lineStart),
54+
std::string(length, '^'),
55+
m_index - std::min(lineStart, m_index)
56+
);
5257
}
5358

5459
private:

include/rift/errors/runtime.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ namespace rift {
4747
while (lineEnd > m_endIndex && source[lineEnd] == ' ') {
4848
lineEnd--;
4949
}
50-
51-
return fmt::format("{}\n{}\n{:>{}}", m_message, source.substr(lineStart, lineEnd - lineStart), std::string(length, '^'), m_index - lineStart);
50+
return fmt::format(
51+
"{}\n{}\n{:>{}}",
52+
m_message,
53+
source.substr(lineStart, lineEnd - lineStart),
54+
std::string(length, '^'),
55+
m_index - std::min(lineStart, m_index)
56+
);
5257
}
5358

5459
private:

0 commit comments

Comments
 (0)