Skip to content

Commit bdc58ee

Browse files
igfooCopilot
andcommitted
Kotlin: Move equivalentTrap's read loop out of use lambdas
The Kotlin 2.5 compiler no longer accepts an endless `while (true)` loop, nested inside inline `use { }` lambdas, as the end of a function returning Boolean, and reports "missing return statement". Move the line comparison loop into a helper, equivalentTrapLines, so that it is the function body itself. Behaviour is unchanged, and this compiles with all supported Kotlin versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 38400d2f-9060-4b63-8536-73ce77bb5c91
1 parent 57adf71 commit bdc58ee

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

‎java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,21 +331,20 @@ This function determines whether 2 TRAP files should be considered to be
331331
equivalent. It returns `true` iff all of their non-comment lines are
332332
identical.
333333
*/
334-
private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean {
335-
r1.use { br1 ->
336-
r2.use { br2 ->
337-
while (true) {
338-
val l1 = br1.readLine()
339-
val l2 = br2.readLine()
340-
if (l1 == null && l2 == null) {
341-
return true
342-
} else if (l1 == null || l2 == null) {
343-
return false
344-
} else if (l1 != l2) {
345-
if (!l1.startsWith("//") || !l2.startsWith("//")) {
346-
return false
347-
}
348-
}
334+
private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean =
335+
r1.use { br1 -> r2.use { br2 -> equivalentTrapLines(br1, br2) } }
336+
337+
private fun equivalentTrapLines(br1: BufferedReader, br2: BufferedReader): Boolean {
338+
while (true) {
339+
val l1 = br1.readLine()
340+
val l2 = br2.readLine()
341+
if (l1 == null && l2 == null) {
342+
return true
343+
} else if (l1 == null || l2 == null) {
344+
return false
345+
} else if (l1 != l2) {
346+
if (!l1.startsWith("//") || !l2.startsWith("//")) {
347+
return false
349348
}
350349
}
351350
}

0 commit comments

Comments
 (0)