source: fix crash when len(source) is zero!

This commit is contained in:
Antoine Viallon 2024-01-11 18:49:27 +01:00
parent c2751847d8
commit 6778a5e5c8
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -126,7 +126,7 @@ class SourceLocation:
def show_in_source(self) -> str:
source = self.source.splitlines(keepends=False)
line_number_maxlen = int(math.log10(len(source)) + 1)
line_number_maxlen = 1 if not len(source) else int(math.log10(len(source)) + 1)
lines = source[self.begin.line:self.end.line + 1]
result = []
begin_char = self.begin.character