From 6170d833011c8de00e778e17b5534ae7221ca44b Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Tue, 4 Apr 2023 23:10:31 +0200 Subject: [PATCH] [FIR] update reversed testData ^KT-56543 --- .../compiler/based/LLFirIdenticalChecker.kt | 44 +------------------ ...ersedDiagnosticCompilerTestDataSpecTest.kt | 2 + ...dReversedDiagnosticCompilerTestDataTest.kt | 40 +++++++++++++++++ .../implicitTypes.reversed.fir.txt | 4 +- .../implicitTypes.reversed.kt | 2 +- .../backingFieldVisibility.reversed.fir.txt | 6 +-- .../backingFieldVisibility.reversed.kt | 6 +-- ...ldWithSmartTypeParameters.reversed.fir.txt | 4 +- ...ngFieldWithSmartTypeParameters.reversed.kt | 2 +- ...PrivateBackingFieldAccess.reversed.fir.txt | 4 +- .../filePrivateBackingFieldAccess.reversed.kt | 2 +- .../propertyTypeNarrowing.reversed.fir.txt | 6 +-- .../propertyTypeNarrowing.reversed.kt | 2 +- .../FreeFunctionCalledAsExtension.reversed.kt | 2 +- ...rsivelyAnnotatedGlobalFunction.reversed.kt | 4 +- .../kotlinJavaKotlinCycle.reversed.kt | 2 +- .../kotlinJavaNestedCycle.reversed.kt | 2 +- .../recursiveType.reversed.kt | 4 +- .../tests/delegation/kt49477.reversed.kt | 6 +-- .../tests/delegation/kt49477Error.reversed.kt | 6 +-- .../recursiveCalls/kt23531.reversed.kt | 8 ++-- .../syntheticPropertyOverridden2.reversed.kt | 2 +- ...endentTypeParametersFromKotlin.reversed.kt | 2 +- .../nonProjectedInnerErasure.reversed.kt | 2 +- .../tests/typeParameters/kt46186.reversed.kt | 2 +- .../importFromTypeAliasObject.reversed.kt | 4 +- .../importMemberFromJavaViaAlias.reversed.kt | 2 +- .../starImportOnTypeAlias.reversed.kt | 2 +- .../delegates/kt50994.reversed.fir.txt | 8 ++-- .../inference/delegates/kt50994.reversed.kt | 4 +- .../handlers/AbstractFirIdenticalChecker.kt | 42 +++++++++++++++++- .../fir/handlers/FirIdenticalChecker.kt | 4 +- .../fir/FirOldFrontendMetaConfigurator.kt | 4 +- 33 files changed, 140 insertions(+), 96 deletions(-) diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LLFirIdenticalChecker.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LLFirIdenticalChecker.kt index d6dd6d586b7..5d63cb8c6ee 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LLFirIdenticalChecker.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LLFirIdenticalChecker.kt @@ -1,19 +1,15 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.analysis.low.level.api.fir.compiler.based -import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.frontend.fir.handlers.AbstractFirIdenticalChecker -import org.jetbrains.kotlin.test.model.TestFile import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.assertions -import org.jetbrains.kotlin.test.services.sourceFileProvider import org.jetbrains.kotlin.test.utils.isLLFirTestData import java.io.File -import kotlin.test.assertEquals /** * `.ll.kt` test data should not be identical to its base `.fir.kt`/`.kt` test data. If a base `.fir.kt` file does not exist, the base file @@ -39,47 +35,11 @@ class LLFirIdenticalChecker(testServices: TestServices) : AbstractFirIdenticalCh "`${testDataFile.name}` and `${baseFile.name}` are identical. Remove `$testDataFile`." } } else { - assertPreprocessedTestDataAreEqual(baseFile, baseContent, testDataFile, llContent) { + assertPreprocessedTestDataAreEqual(testServices, baseFile, baseContent, testDataFile, llContent) { "When ignoring diagnostics, the contents of `${baseFile.name}` (expected) and `${testDataFile.name}` (actual) are not" + " identical. `.ll.kt` test data may only differ from its base `.fir.kt` or `.kt` test data in the reported" + " diagnostics and the `LL_FIR_DIVERGENCE` directive. Update one of these test data files." } } } - - /** - * Asserts that [baseFile] and [llFile] have the same content after preprocessing (which removes diagnostics and other meta info). This - * prevents situations where one test data changes, but changes to the other test data are forgotten. - * - * [llContent] should have its `LL_FIR_DIVERGENCE` directive already removed. - */ - private fun assertPreprocessedTestDataAreEqual( - baseFile: File, - baseContent: String, - llFile: File, - llContent: String, - message: () -> String, - ) { - val processedBaseContent = testServices.sourceFileProvider.getContentOfSourceFile( - TestFile( - baseFile.path, - baseContent, - baseFile, - startLineNumberInOriginalFile = 0, - isAdditional = false, - RegisteredDirectives.Empty, - ) - ) - val processedLlContent = testServices.sourceFileProvider.getContentOfSourceFile( - TestFile( - llFile.path, - llContent, - llFile, - startLineNumberInOriginalFile = 0, - isAdditional = false, - RegisteredDirectives.Empty, - ) - ) - assertEquals(processedBaseContent, processedLlContent, message()) - } } \ No newline at end of file diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataSpecTest.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataSpecTest.kt index dc990058aad..d8984f89d9e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataSpecTest.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataSpecTest.kt @@ -18,5 +18,7 @@ abstract class AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataSpecTes ) baseFirSpecDiagnosticTestConfigurationForIde() useAfterAnalysisCheckers(::FirReversedSuppressor) + useMetaTestConfigurators(::ReversedDiagnosticsConfigurator) + useAfterAnalysisCheckers(::ReversedFirIdenticalChecker) } } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest.kt index 0b1260dc6db..c55da5e7979 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based +import java.io.File import org.jetbrains.kotlin.analysis.low.level.api.fir.compiler.based.AbstractCompilerBasedTestForFir import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.facades.LLFirAnalyzerFacadeFactoryWithPreresolveInReversedOrder import org.jetbrains.kotlin.test.bind @@ -14,8 +15,13 @@ import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.WrappedException import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer +import org.jetbrains.kotlin.test.frontend.fir.handlers.AbstractFirIdenticalChecker import org.jetbrains.kotlin.test.model.AfterAnalysisChecker +import org.jetbrains.kotlin.test.services.MetaTestConfigurator +import org.jetbrains.kotlin.test.services.assertions import org.jetbrains.kotlin.test.services.moduleStructure +import org.jetbrains.kotlin.test.utils.firTestDataFile +import org.jetbrains.kotlin.test.utils.llFirTestDataFile abstract class AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest : AbstractCompilerBasedTestForFir() { override fun TestConfigurationBuilder.configureTest() { @@ -24,6 +30,15 @@ abstract class AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest : ) useAfterAnalysisCheckers(::FirReversedSuppressor) + useMetaTestConfigurators(::ReversedDiagnosticsConfigurator) + useAfterAnalysisCheckers(::ReversedFirIdenticalChecker) + } +} + +internal class ReversedDiagnosticsConfigurator(testServices: TestServices) : MetaTestConfigurator(testServices) { + override fun transformTestDataPath(testDataFileName: String): String { + val reversedTestDataFileName = testDataFileName.replaceFirst(".", ".reversed.") + return if (File(reversedTestDataFileName).exists()) reversedTestDataFileName else testDataFileName } } @@ -52,3 +67,28 @@ internal class FirReversedSuppressor(testServices: TestServices) : AfterAnalysis val IGNORE_REVERSED_RESOLVE by directive("Temporary disables reversed resolve checks until the issue is fixed") } } + +class ReversedFirIdenticalChecker(testServices: TestServices) : AbstractFirIdenticalChecker(testServices) { + override fun checkTestDataFile(testDataFile: File) { + if (".reversed." !in testDataFile.path) return + + val originalFile = helper.getClassicFileToCompare(testDataFile).path.replace(".reversed", "").let(::File) + val baseFile = originalFile.llFirTestDataFile.takeIf(File::exists) + ?: originalFile.firTestDataFile.takeIf(File::exists) + ?: originalFile + + val baseContent = helper.readContent(baseFile, trimLines = false) + val reversedFirContent = helper.readContent(testDataFile, trimLines = false) + if (baseContent == reversedFirContent) { + testServices.assertions.fail { + "`${testDataFile.name}` and `${baseFile.name}` are identical. Remove `$testDataFile`." + } + } else { + assertPreprocessedTestDataAreEqual(testServices, baseFile, baseContent, testDataFile, reversedFirContent) { + "When ignoring diagnostics, the contents of `${baseFile.name}` (expected) and `${testDataFile.name}` (actual) are not" + + " identical. `.reversed.kt` test data may only differ from its base `.fir.kt` or `.kt` test data in the reported" + + " diagnostics. Update one of these test data files." + } + } + } +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.fir.txt index 4ea0a252edf..c978e7c8600 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.fir.txt @@ -1,4 +1,4 @@ -FILE: implicitTypes.kt +FILE: implicitTypes.reversed.kt public final fun use(x: R|(T) -> R|): R|(T) -> R| { ^use R|/x| } @@ -11,6 +11,6 @@ FILE: implicitTypes.kt public final fun loop1(): R|(ERROR CLASS: Cannot infer argument for type parameter T) -> ERROR CLASS: Cannot infer argument for type parameter R| { ^loop1 R|/use#|<, >(::#) } - public final fun loop2(): { + public final fun loop2(): R|(ERROR CLASS: Cannot infer argument for type parameter T) -> ERROR CLASS: Cannot infer argument for type parameter R| { ^loop2 R|/loop1|() } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.kt index 6298db84ebc..590d4b2f871 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.reversed.kt @@ -4,4 +4,4 @@ fun foo() = use(::bar) fun bar(x: String) = 1 fun loop1() = use(::loop2) -fun loop2() = loop1() +fun loop2() = loop1() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.fir.txt index 2942fb461c5..a404fba8684 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.fir.txt @@ -22,8 +22,8 @@ FILE: A.kt public get(): R|kotlin/Number| public final fun rest(): R|kotlin/Unit| { - lval aI: R|kotlin/Int| = R|/A.A|().R|/A.a|.R|kotlin/Int.plus|(Int(10)) - lval bI: R|kotlin/Int| = R|/A.A|().R|/A.b|.R|kotlin/Int.plus|(Int(20)) + lval aI: = R|/A.A|().R|/A.a|.#(Int(10)) + lval bI: = R|/A.A|().R|/A.b|.#(Int(20)) lval cI: = R|/A.A|().R|/A.c|.#(Int(30)) lval dI: = R|/A.A|().R|/A.d|.#(Int(40)) } @@ -31,7 +31,7 @@ FILE: A.kt } public final fun test(): R|kotlin/Unit| { lval aA: = R|/A.A|().R|/A.a|.#(Int(10)) - lval bA: R|kotlin/Int| = R|/A.A|().R|/A.b|.R|kotlin/Int.plus|(Int(20)) + lval bA: = R|/A.A|().R|/A.b|.#(Int(20)) lval cA: = R|/A.A|().R|/A.c|.#(Int(30)) lval dA: = R|/A.A|().R|/A.d|.#(Int(40)) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.kt index 963c85ae7c9..ff162300e6e 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.reversed.kt @@ -15,8 +15,8 @@ class A { public field = 5 fun rest() { - val aI = A().a + 10 - val bI = A().b + 20 + val aI = A().a + 10 + val bI = A().b + 20 val cI = A().c + 30 val dI = A().d + 40 } @@ -24,7 +24,7 @@ class A { fun test() { val aA = A().a + 10 - val bA = A().b + 20 + val bA = A().b + 20 val cA = A().c + 30 val dA = A().d + 40 } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.fir.txt index c41ad3dee9e..ab1223bb9da 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.fir.txt @@ -1,7 +1,7 @@ -FILE: backingFieldWithSmartTypeParameters.kt +FILE: backingFieldWithSmartTypeParameters.reversed.kt public final val items: R|kotlin/collections/List| private : R|kotlin/collections/MutableList| = R|kotlin/collections/mutableListOf|() public get(): R|kotlin/collections/List| public final fun test(): R|kotlin/Unit| { - R|/items|.R|SubstitutionOverride|(String(one more item)) + R|/items|.#(String(one more item)) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.kt index 7fe46de630b..992dc66e6bf 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.reversed.kt @@ -2,5 +2,5 @@ val items: List field = mutableListOf() fun test() { - items.add("one more item") + items.add("one more item") } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.fir.txt index f8daf7214ed..bf6e55950b4 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.fir.txt @@ -1,7 +1,7 @@ -FILE: filePrivateBackingFieldAccess.kt +FILE: filePrivateBackingFieldAccess.reversed.kt public final val list: R|kotlin/collections/List| private : R|kotlin/collections/MutableList| = R|kotlin/collections/mutableListOf|() public get(): R|kotlin/collections/List| public final fun add(s: R|kotlin/String|): R|kotlin/Unit| { - R|/list|.R|SubstitutionOverride|(R|/s|) + R|/list|.#(R|/s|) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.kt index d71b5697aaa..da7f4a9e139 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.reversed.kt @@ -2,5 +2,5 @@ val list: List field = mutableListOf() fun add(s: String) { - list.add(s) + list.add(s) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.fir.txt index e7d9ed0cae0..61612aad46c 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.fir.txt @@ -1,4 +1,4 @@ -FILE: propertyTypeNarrowing.kt +FILE: propertyTypeNarrowing.reversed.kt public final class A : R|kotlin/Any| { public constructor(): R|A| { super() @@ -8,8 +8,8 @@ FILE: propertyTypeNarrowing.kt private : R|kotlin/Int| = Int(4) public get(): R|kotlin/Number| - public final fun test(): R|kotlin/Int| { - ^test this@R|/A|.R|/A.it|.R|kotlin/Int.plus|(Int(3)) + public final fun test(): { + ^test this@R|/A|.R|/A.it|.#(Int(3)) } public final val p: R|kotlin/Int| = Int(5) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.kt index ebd1d9e3ca0..45758209769 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.reversed.kt @@ -2,7 +2,7 @@ class A { val it: Number field = 4 - fun test() = it + 3 + fun test() = it + 3 val p = 5 get() = field diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt index 140ff3919a6..b742d3ccb3c 100644 --- a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt +++ b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt @@ -10,5 +10,5 @@ typealias AliasedEFT = ExtensionFunctionType fun foo(a: @AliasedEFT A) { // @Extension annotation on an unrelated type shouldn't have any effect on this diagnostic. // Only kotlin.Function{n} type annotated with @Extension should - "".a() + "".a() } diff --git a/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.reversed.kt b/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.reversed.kt index 240fc6e4d79..17c6c2a5362 100644 --- a/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.reversed.kt +++ b/compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.reversed.kt @@ -1,4 +1,4 @@ // Functions can be recursively annotated annotation class ann(val x: Int) -@ann(bar()) fun foo() = 1 -@ann(foo()) fun bar() = 2 \ No newline at end of file +@ann(bar()) fun foo() = 1 +@ann(foo()) fun bar() = 2 diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.reversed.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.reversed.kt index 450445819cf..d2a49a6099f 100644 --- a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.reversed.kt +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaKotlinCycle.reversed.kt @@ -15,6 +15,6 @@ class J extends I { // FILE: K.kt -open class K : J() { +open class K : J() { fun baz() {} } diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.reversed.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.reversed.kt index 208e0735310..1edd2e30e6d 100644 --- a/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.reversed.kt +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/kotlinJavaNestedCycle.reversed.kt @@ -1,6 +1,6 @@ // FILE: ExceptionTracker.kt -interface ExceptionTracker : LockBasedStorageManager.ExceptionHandlingStrategy { +interface ExceptionTracker : LockBasedStorageManager.ExceptionHandlingStrategy { } // FILE: StorageManager.kt diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.reversed.kt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.reversed.kt index 0ca79449c41..a2266826997 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.reversed.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.reversed.kt @@ -7,8 +7,8 @@ val a by b) -val c by d -val d by c +val c by d +val d by c class Delegate(i: Int) { operator fun getValue(t: Any?, p: KProperty<*>): Int { diff --git a/compiler/testData/diagnostics/tests/delegation/kt49477.reversed.kt b/compiler/testData/diagnostics/tests/delegation/kt49477.reversed.kt index 45014c3ecde..45fd5c769f3 100644 --- a/compiler/testData/diagnostics/tests/delegation/kt49477.reversed.kt +++ b/compiler/testData/diagnostics/tests/delegation/kt49477.reversed.kt @@ -8,7 +8,7 @@ inline fun Self property: KProperty1>): Delegate = TODO() class GitLabBuildProcessor: DatabaseEntity { - var processor by parent(GitLabChangesProcessor::buildProcessors) + var processor by parent(GitLabChangesProcessor::buildProcessors) } interface DatabaseEntity: Entity @@ -24,9 +24,9 @@ infix fun filter(filter: (R, Any?) -> Boolean): Delegate } class GitLabChangesProcessor: DatabaseEntity { - var buildProcessors by child_many( + var buildProcessors by child_many( GitLabBuildProcessor::class.java, - GitLabBuildProcessor::processor + GitLabBuildProcessor::processor ) } diff --git a/compiler/testData/diagnostics/tests/delegation/kt49477Error.reversed.kt b/compiler/testData/diagnostics/tests/delegation/kt49477Error.reversed.kt index e99e8bdb576..884bfc852b8 100644 --- a/compiler/testData/diagnostics/tests/delegation/kt49477Error.reversed.kt +++ b/compiler/testData/diagnostics/tests/delegation/kt49477Error.reversed.kt @@ -9,7 +9,7 @@ inline fun Self property: KProperty1>): Delegate = TODO() class GitLabBuildProcessor: DatabaseEntity { - var processor by parent(GitLabChangesProcessor::buildProcessors) + var processor by parent(GitLabChangesProcessor::buildProcessors) } interface DatabaseEntity: Entity @@ -25,9 +25,9 @@ infix fun filter(filter: (R, Any?) -> Boolean): Delegate } class GitLabChangesProcessor: DatabaseEntity { - var buildProcessors by child_many( + var buildProcessors by child_many( GitLabBuildProcessor::class.java, - GitLabBuildProcessor::processor + GitLabBuildProcessor::processor ) } diff --git a/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.reversed.kt b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.reversed.kt index 68c66797f5d..b8772de7e7d 100644 --- a/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.reversed.kt +++ b/compiler/testData/diagnostics/tests/inference/recursiveCalls/kt23531.reversed.kt @@ -7,10 +7,10 @@ fun simpleAsync1(block: suspend Scope.() -> T) {} suspend fun simpleAsync2(block: Scope.() -> T) {} suspend fun simpleAsync3(block: suspend Scope.() -> T) {} -fun insideJob0() = doTheJob0() -fun insideJob1() = doTheJob1() -suspend fun insideJob2() = doTheJob2() -suspend fun insideJob3() = doTheJob3() +fun insideJob0() = doTheJob0() +fun insideJob1() = doTheJob1() +suspend fun insideJob2() = doTheJob2() +suspend fun insideJob3() = doTheJob3() fun doTheJob0() = simpleAsync0 { insideJob0() } fun doTheJob1() = simpleAsync1 { insideJob1() } diff --git a/compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.reversed.kt b/compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.reversed.kt index bcaf683633d..7c311ad9cf4 100644 --- a/compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.reversed.kt +++ b/compiler/testData/diagnostics/tests/j+k/syntheticPropertyOverridden2.reversed.kt @@ -29,5 +29,5 @@ fun modality(): Modality = Modality.FINAL class DeserializedClassDescriptor2 : ClassDescriptor { private val modality = modality() - override fun getModality() = modality + override fun getModality() = modality } diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interdependentTypeParametersFromKotlin.reversed.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interdependentTypeParametersFromKotlin.reversed.kt index e35849f58bf..10b3ccb01a6 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interdependentTypeParametersFromKotlin.reversed.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/interdependentTypeParametersFromKotlin.reversed.kt @@ -8,5 +8,5 @@ class Foo, P2 : Boo, P3 : Boo, P4 : // FILE: main.kt fun main() { - val x = >, Boo<*, *, *>>, Boo<*, *, Boo<*, *, *>>, Boo<*, *, *>>, Boo<*, Boo<*, *, Boo<*, *, *>>, Boo<*, *, *>>, Boo<*, *, Boo<*, *, *>>, Boo<*, *, *>>..Foo<*, *, *, *>?!")!>Boo.test1() + val x = ..Foo<*, *, *, *>?!")!>Boo.test1() } diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonProjectedInnerErasure.reversed.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonProjectedInnerErasure.reversed.kt index 87bba19b3ac..2020258543d 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonProjectedInnerErasure.reversed.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonProjectedInnerErasure.reversed.kt @@ -13,5 +13,5 @@ fun applyEditorTo(arg: CidrRunConfiguration>) {} fun main() { // Previously, for CidrRunConfiguration raw type, it's lower bound was resolved as CidrRunConfiguration> in K2 // That is not a subtype of CidrRunConfiguration> - applyEditorTo(CustomGdbServerRunConfiguration()) // K1: ok, K2: was ARGUMENT_TYPE_MISMATCH + applyEditorTo(CustomGdbServerRunConfiguration()) // K1: ok, K2: was ARGUMENT_TYPE_MISMATCH } diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt46186.reversed.kt b/compiler/testData/diagnostics/tests/typeParameters/kt46186.reversed.kt index 20a9e1bba95..2a66b05ca95 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/kt46186.reversed.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/kt46186.reversed.kt @@ -71,7 +71,7 @@ object Obj { fun test9(): View1 = findViewById9() inline fun findViewById10(): T where T: View3, T: View5 = null as T - fun test10(): View1 = findViewById10() + fun test10(): View1 = findViewById10() fun findViewById11(): T = null as T fun test11(): View4 = findViewById11() diff --git a/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.reversed.kt b/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.reversed.kt index eb29413f66a..4a8243d6368 100644 --- a/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.reversed.kt +++ b/compiler/testData/diagnostics/tests/typealias/importFromTypeAliasObject.reversed.kt @@ -12,5 +12,5 @@ object Host { import bar.HostAlias.foo fun test() { - foo() -} \ No newline at end of file + foo() +} diff --git a/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.reversed.kt b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.reversed.kt index 8c4115c85b5..5dc659160fd 100644 --- a/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.reversed.kt +++ b/compiler/testData/diagnostics/tests/typealias/importMemberFromJavaViaAlias.reversed.kt @@ -25,5 +25,5 @@ fun foo( sample: JavaSample, alias: JavaAlias ) { - member() + member() } diff --git a/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.reversed.kt b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.reversed.kt index ea3d6ab50cc..903732e2ac3 100644 --- a/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.reversed.kt +++ b/compiler/testData/diagnostics/tests/typealias/starImportOnTypeAlias.reversed.kt @@ -23,6 +23,6 @@ import test.EnumAlias fun bar() { - Entry + Entry EnumAlias.Entry } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.fir.txt index 2db301ef395..541db736496 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.fir.txt @@ -1,4 +1,4 @@ -FILE: kt50994.fir.kt +FILE: kt50994.reversed.kt public final class ProcessorWithParent : R|Entity| { public constructor(): R|ProcessorWithParent| { super() @@ -18,11 +18,11 @@ FILE: kt50994.fir.kt super() } - public final var processors: R|kotlin/collections/MutableCollection|by this@R|/ProcessorWithChildren|.R|/children#|<, >((Q|ProcessorWithParent|).R|kotlin/jvm/java|, Q|ProcessorWithParent|::#) - public get(): R|kotlin/collections/MutableCollection| { + public final var processors: R|kotlin/collections/MutableCollection|by this@R|/ProcessorWithChildren|.R|/children|((Q|ProcessorWithParent|).R|kotlin/jvm/java|, Q|ProcessorWithParent|::R|/ProcessorWithParent.processor|) + public get(): R|kotlin/collections/MutableCollection| { ^ this@R|/ProcessorWithChildren|.D|/ProcessorWithChildren.processors|.R|SubstitutionOverride|>|(this@R|/ProcessorWithChildren|, ::R|/ProcessorWithChildren.processors|) } - public set(: R|kotlin/collections/MutableCollection|): R|kotlin/Unit| { + public set(: R|kotlin/collections/MutableCollection|): R|kotlin/Unit| { this@R|/ProcessorWithChildren|.D|/ProcessorWithChildren.processors|.R|SubstitutionOverride|(this@R|/ProcessorWithChildren|, ::R|/ProcessorWithChildren.processors|, R|/processors|) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.kt index 88b67ef10c0..c36a8ad614a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt50994.reversed.kt @@ -5,11 +5,11 @@ import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty1 class ProcessorWithParent : Entity { - var processor by parent(ProcessorWithChildren::processors) + var processor by parent(ProcessorWithChildren::processors) } class ProcessorWithChildren : Entity { - var processors by children(ProcessorWithParent::class.java, ProcessorWithParent::processor) + var processors by children(ProcessorWithParent::class.java, ProcessorWithParent::processor) } class Processor2WithParent : Entity { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/AbstractFirIdenticalChecker.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/AbstractFirIdenticalChecker.kt index 81bb762ea61..883df21003b 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/AbstractFirIdenticalChecker.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/AbstractFirIdenticalChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -13,6 +13,10 @@ import org.jetbrains.kotlin.test.utils.FirIdenticalCheckerHelper import org.jetbrains.kotlin.test.utils.firTestDataFile import org.jetbrains.kotlin.test.utils.originalTestDataFile import java.io.File +import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives +import org.jetbrains.kotlin.test.model.TestFile +import org.jetbrains.kotlin.test.services.assertions +import org.jetbrains.kotlin.test.services.sourceFileProvider abstract class AbstractFirIdenticalChecker(testServices: TestServices) : AfterAnalysisChecker(testServices) { protected inner class SpecificHelper : FirIdenticalCheckerHelper(testServices) { @@ -29,4 +33,40 @@ abstract class AbstractFirIdenticalChecker(testServices: TestServices) : AfterAn val testDataFile = testServices.moduleStructure.originalTestDataFiles.first() checkTestDataFile(testDataFile) } + + /** + * Asserts that [baseFile] and [customFile] have the same content after preprocessing (which removes diagnostics and other meta info). This + * prevents situations where one test data changes, but changes to the other test data are forgotten. + */ + protected fun assertPreprocessedTestDataAreEqual( + testServices: TestServices, + baseFile: File, + baseContent: String, + customFile: File, + customContent: String, + message: () -> String, + ) { + val processedBaseContent = testServices.sourceFileProvider.getContentOfSourceFile( + TestFile( + baseFile.path, + baseContent, + baseFile, + startLineNumberInOriginalFile = 0, + isAdditional = false, + RegisteredDirectives.Empty, + ) + ) + val processedLlContent = testServices.sourceFileProvider.getContentOfSourceFile( + TestFile( + customFile.path, + customContent, + customFile, + startLineNumberInOriginalFile = 0, + isAdditional = false, + RegisteredDirectives.Empty, + ) + ) + + testServices.assertions.assertEquals(processedBaseContent, processedLlContent, message) + } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirIdenticalChecker.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirIdenticalChecker.kt index a7ec70d30fc..4b4a38b43c3 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirIdenticalChecker.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirIdenticalChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -17,6 +17,8 @@ class FirIdenticalChecker(testServices: TestServices) : AbstractFirIdenticalChec if (testDataFile.isFirTestData) { val classicFile = helper.getClassicFileToCompare(testDataFile) + if (".reversed." in classicFile.path) return + if (helper.contentsAreEquals(classicFile, testDataFile, trimLines = true)) { helper.deleteFirFile(testDataFile) helper.addDirectiveToClassicFileAndAssert(classicFile) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/fir/FirOldFrontendMetaConfigurator.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/fir/FirOldFrontendMetaConfigurator.kt index 4c8fb6484d8..0df2972c6a2 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/fir/FirOldFrontendMetaConfigurator.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/fir/FirOldFrontendMetaConfigurator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -18,7 +18,7 @@ class FirOldFrontendMetaConfigurator(testServices: TestServices) : MetaTestConfi // Skip `.ll.kt` tests, whose path is provided by `LLFirMetaTestConfigurator`. Because `FirOldFrontendMetaConfigurator` is usually // configured with `forTestsMatching`, it'll be executed after `LLFirMetaTestConfigurator`, which is configured generally. - if (originalFile.isLLFirTestData) return testDataFileName + if (originalFile.isLLFirTestData || ".reversed." in originalFile.path) return testDataFileName val isFirIdentical = originalFile.useLines { lines -> lines.any { it == "// ${FirDiagnosticsDirectives.FIR_IDENTICAL.name}" } } return if (isFirIdentical) {