Skip to content

Commit 3e099c3

Browse files
authored
Merge pull request #13274 from BarkingBad/backport-sourclink-fixes
2 parents 0088a23 + e6697c3 commit 3e099c3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ class TreeUnpickler(reader: TastyReader,
13991399
if (path.nonEmpty) {
14001400
val sourceFile = ctx.getSource(path)
14011401
posUnpicklerOpt match
1402-
case Some(posUnpickler) =>
1402+
case Some(posUnpickler) if !sourceFile.initizlized =>
14031403
sourceFile.setLineIndicesFromLineSizes(posUnpickler.lineSizes)
14041404
case _ =>
14051405
pickling.println(i"source change at $addr: $path")

compiler/src/dotty/tools/dotc/util/SourceFile.scala

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
144144
if lineIndicesCache eq null then
145145
lineIndicesCache = calculateLineIndicesFromContents()
146146
lineIndicesCache
147+
148+
def initizlized = lineIndicesCache != null
149+
147150
def setLineIndicesFromLineSizes(sizes: Array[Int]): Unit =
148151
val lines = sizes.length
149152
val indices = new Array[Int](lines + 1)

scaladoc/test-source-links/dotty/tools/scaladoc/source-links/RemoteLinksTest.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ class RemoteLinksTest:
3838
def runTest =
3939
assertTrue(mtslAll.nonEmpty)
4040
val mtsl = randomGenerator.shuffle(mtslAll).take(80) // take 80 random entries
41-
val pageToMtsl: Map[String, List[(String, String)]] = mtsl.groupMap(_._2.split("#L").head)(v => (v._1, v._2.split("#L").last))
42-
pageToMtsl.foreach { case (link, members) =>
41+
val pageToMtsl: Map[String, List[(String, Int)]] =
42+
mtsl.groupMap(_._2.split("#L").head)(v => (v._1, v._2.split("#L").last.toInt))
43+
pageToMtsl.toSeq.sortBy(_._1).foreach { case (link, members) =>
4344
try
4445
val doc = getDocumentFromUrl(link)
4546
println(s"Checking $link")
4647
members.foreach { case (member, expectedLine) =>
4748
if !member.startsWith("given_") then // TODO: handle synthetic givens, for now we disable them from testing
4849
val toLine = expectedLine + 3
4950
val memberToMatch = member.replace("`", "")
50-
val lineCorrectlyDefined = (expectedLine.toInt until toLine.toInt).exists{ line =>
51+
val lineCorrectlyDefined = (expectedLine until toLine).exists{ line =>
5152
val loc = doc.select(s"#LC$line").text
5253

5354
loc.contains(memberToMatch)

0 commit comments

Comments
 (0)