diff --git a/src/compiler/crystal/exception.cr b/src/compiler/crystal/exception.cr index 87ac61325e22..a8853888660a 100644 --- a/src/compiler/crystal/exception.cr +++ b/src/compiler/crystal/exception.cr @@ -253,8 +253,8 @@ module Crystal source, _ = minimize_indentation(source.lines) io << Crystal.with_line_numbers(source, line_number, @color) else - from_index = {0, line_number - MACRO_LINES_TO_SHOW}.max - to_index = {source.lines.size, line_number}.max + to_index = line_number.clamp(0..source.lines.size) + from_index = {0, to_index - MACRO_LINES_TO_SHOW}.max source_slice = source.lines[from_index...to_index] source_slice, spaces_removed = minimize_indentation(source_slice)