Skip to content

Commit 244317f

Browse files
Merge pull request #15121 from dotty-staging/fix-14795
add comments for length and content().length in SourceFile
2 parents 61b53ec + f369413 commit 244317f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
6464

6565
private var myContent: Array[Char] | Null = null
6666

67+
/** The contents of the original source file. Note that this can be empty, for example when
68+
* the source is read from Tasty. */
6769
def content(): Array[Char] = {
6870
if (myContent == null) myContent = computeContent
6971
myContent
@@ -92,6 +94,9 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
9294

9395
def apply(idx: Int): Char = content().apply(idx)
9496

97+
/** length of the original source file
98+
* Note that when the source is from Tasty, content() could be empty even though length > 0.
99+
* Use content().length to determine the length of content(). */
95100
def length: Int =
96101
if lineIndicesCache ne null then lineIndicesCache.last
97102
else content().length

0 commit comments

Comments
 (0)