From 10e94f90ac1b2396d0427d9078c1fe481859cb60 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 5 Sep 2023 17:02:39 +0200 Subject: [PATCH] [Tests] Trim contents before checking for FIR_IDENTICAL --- ...WithDefaultValueAsOtherFunctionType.fir.kt | 17 -------- ...enceWithDefaultValueAsOtherFunctionType.kt | 1 + .../approximateBeforeFixation.fir.kt | 8 ---- .../approximateBeforeFixation.kt | 1 + .../inference/fixVariableToNothing.fir.kt | 15 ------- .../tests/inference/fixVariableToNothing.kt | 1 + .../testsWithStdLib/inference/kt27772.fir.kt | 8 ---- .../testsWithStdLib/inference/kt27772.kt | 1 + .../when/noTypeArgumentsInConstructor.fir.kt | 42 ------------------- .../when/noTypeArgumentsInConstructor.kt | 1 + .../test/utils/FirIdenticalCheckerHelper.kt | 3 +- 11 files changed, 7 insertions(+), 91 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt deleted file mode 100644 index e56e0ef3837..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ - -fun foo(a: String, b: Int = 5): String { - return a + b -} - -fun bar1(body: (String) -> String): String { - return body("something") -} - -fun bar2(body: (String, Int) -> String): String { - return body("something", 0) -} - -fun test() { - bar1(::foo) - bar2(::foo) -} diff --git a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.kt b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.kt index ad0711f7944..30db4b8ed4b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/functionReferenceWithDefaultValueAsOtherFunctionType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun foo(a: String, b: Int = 5): String { return a + b } diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt deleted file mode 100644 index d8f3fda3b6d..00000000000 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ - -fun Array.intersect(other: Iterable) { - val set = toMutableSet() - set.retainAll(other) -} - -fun Array.toMutableSet(): MutableSet = TODO() -fun MutableCollection.retainAll(elements: Iterable) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.kt index 5fc841c5053..81d0071f0eb 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximateBeforeFixation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun Array.intersect(other: Iterable) { val set = toMutableSet() set.retainAll(other) diff --git a/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt b/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt deleted file mode 100644 index 3e1d827150f..00000000000 --- a/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ - -// completion order here: X, Y, WHEN_VARIABLE -fun List.optimizeReadOnlyList() = when (size) { - 0 -> emptyList() // here type variable Y will be fixed to Nothing - 1 -> listOf(this[0]) - else -> this -} -fun listOf(element: X): List = TODO() -fun emptyList(): List = TODO() - - -fun test(l: List): List { - val foo = l.optimizeReadOnlyList() - return foo -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.kt b/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.kt index 470d955e73f..7b2e8a8ad9d 100644 --- a/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.kt +++ b/compiler/testData/diagnostics/tests/inference/fixVariableToNothing.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // completion order here: X, Y, WHEN_VARIABLE fun List.optimizeReadOnlyList() = when (size) { 0 -> emptyList() // here type variable Y will be fixed to Nothing diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt deleted file mode 100644 index eae4bac51fa..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.fir.kt +++ /dev/null @@ -1,8 +0,0 @@ - -fun foo(resources: List) { - resources.map { runCatching { it } }.mapNotNull { it.getOrNull() } -} - -fun bar(resources: List) { - resources.map { runCatching { it } }.mapNotNull { it.getOrNull() } -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.kt index 7f1bc332fe2..aff5243e05f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt27772.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun foo(resources: List) { resources.map { runCatching { it } }.mapNotNull { it.getOrNull() } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt deleted file mode 100644 index cb6beac0ad4..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.fir.kt +++ /dev/null @@ -1,42 +0,0 @@ - -import java.util.* - -fun nullable(x: T): T? = x - -@Suppress("UNUSED_PARAMETER") -fun select(x1: T, x2: T): T = x1 - -val test1 = - listOf(1, 2, 3).mapNotNullTo(ArrayList()) { - if (true) nullable(it) else null - } - -val test2: MutableList = - listOf(1, 2, 3).mapNotNullTo(ArrayList()) { - if (true) nullable(it) else null - } - -val test3: MutableList = - listOf(1, 2, 3).mapNotNullTo(ArrayList()) { - if (true) nullable(it) else null - } - -val test4: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - listOf(it) - } - -val test5: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { // TODO - if (true) listOf(it) else listOf(it) - } - -val test6: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - if (true) listOf(it) else listOf(it) - } - -val test7: Collection = - listOf(1, 2, 3).flatMapTo(LinkedHashSet()) { - select(listOf(it), listOf(it)) - } diff --git a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.kt b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.kt index d8ce98a56cf..5c3c3dc4d05 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/when/noTypeArgumentsInConstructor.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL import java.util.* fun nullable(x: T): T? = x diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/FirIdenticalCheckerHelper.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/FirIdenticalCheckerHelper.kt index ec9696f6adb..1da4b6b6be0 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/FirIdenticalCheckerHelper.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/FirIdenticalCheckerHelper.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.utils import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.assertions +import org.jetbrains.kotlin.utils.addToStdlib.applyIf import java.io.File abstract class FirIdenticalCheckerHelper(private val testServices: TestServices) { @@ -32,7 +33,7 @@ abstract class FirIdenticalCheckerHelper(private val testServices: TestServices) fun readContent(file: File, trimLines: Boolean): String { return if (trimLines) { - file.readLines().joinToString("\n") { it.trimEnd() }.trimEnd() + file.readLines().joinToString("\n") { it.trimEnd() }.trim() } else { file.readText() }