diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index b053b0ea777f..f7b56c246b8c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1399,7 +1399,7 @@ class TreeUnpickler(reader: TastyReader, if (path.nonEmpty) { val sourceFile = ctx.getSource(path) posUnpicklerOpt match - case Some(posUnpickler) => + case Some(posUnpickler) if !sourceFile.initizlized => sourceFile.setLineIndicesFromLineSizes(posUnpickler.lineSizes) case _ => pickling.println(i"source change at $addr: $path") diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index 73fd53289a9b..c1977f99e5c9 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -144,6 +144,9 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends if lineIndicesCache eq null then lineIndicesCache = calculateLineIndicesFromContents() lineIndicesCache + + def initizlized = lineIndicesCache != null + def setLineIndicesFromLineSizes(sizes: Array[Int]): Unit = val lines = sizes.length val indices = new Array[Int](lines + 1)