Skip to content

Commit

Permalink
[IR] Assume IrFile has at least one offset entry
Browse files Browse the repository at this point in the history
This is required for scripting in the case of empty file compilation.
Otherwise, JVM backend will get the wrong (non-positive) line number
and will fail.

#KT-67727 Fixed

(cherry picked from commit 34e3c8e)
  • Loading branch information
ivandev0 authored and qodana-bot committed May 8, 2024
1 parent be1804c commit afc5b49
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PsiIrFileEntry(val psiFile: PsiFile) : AbstractIrFileEntry() {
init {
val document = fileViewProvider.document ?: throw AssertionError("No document for $psiFile")
maxOffset = document.textLength
lineStartOffsets = IntArray(document.lineCount) { document.getLineStartOffset(it) }
lineStartOffsets = IntArray(document.lineCount.takeIf { it != 0 } ?: 1) { document.getLineStartOffset(it) }
}

private fun getRecognizableName(): String = psiFileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ val OUT_FROM_IMPORT_TEST = listOf("Hi from common", "Hi from middle", "Hi from m

class MainKtsTest {

@Test
fun testEmptyFile() {
val res = evalFile(File("$TEST_DATA_ROOT/empty.main.kts"))
assertSucceeded(res)
}

@Test
fun testResolveJunit() {
val res = evalFile(File("$TEST_DATA_ROOT/hello-resolve-junit.main.kts"))
Expand Down
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afc5b49

Please sign in to comment.