Fix off by one in diagnostics printing

This commit is contained in:
nub31
2025-06-07 20:39:06 +02:00
parent 3c3a48d3b4
commit ddb3d7e3c0

View File

@@ -116,10 +116,10 @@ public class Diagnostic
var lineNumWidth = Math.Min(endLine + contextLines, lines.Length).ToString().Length; var lineNumWidth = Math.Min(endLine + contextLines, lines.Length).ToString().Length;
var contextStart = Math.Max(1, startLine - contextLines); var contextStart = Math.Max(1, startLine - contextLines);
var contextEnd = Math.Min(lines.Length, endLine + contextLines); var contextEnd = Math.Min(lines.Length + 1, endLine + contextLines);
var contextWidth = 0; var contextWidth = 0;
for (var i = contextStart; i < contextEnd; i++) for (var i = contextStart; i <= contextEnd; i++)
{ {
if (lines[i - 1].Length > contextWidth) if (lines[i - 1].Length > contextWidth)
{ {