From 050c66ea81d9973b1145d55e67fb271fe73c76cb Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Mon, 3 Jul 2023 16:49:57 +0200 Subject: [PATCH] [FIR] add missing Any super type to Cloneable ^KTIJ-24272 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++ .../impl/FirCloneableSymbolProvider.kt | 16 +++++++--- .../diagnostics/tests/j+k/ktij24272.kt | 29 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ 7 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/j+k/ktij24272.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index a2edf572383..ad322445a45 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -20084,6 +20084,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/j+k/kt7523.kt"); } + @Test + @TestMetadata("ktij24272.kt") + public void testKtij24272() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/ktij24272.kt"); + } + @Test @TestMetadata("matchers.kt") public void testMatchers() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 348734ab993..3ec38525f36 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -20084,6 +20084,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/j+k/kt7523.kt"); } + @Test + @TestMetadata("ktij24272.kt") + public void testKtij24272() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/ktij24272.kt"); + } + @Test @TestMetadata("matchers.kt") public void testMatchers() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 3d68e5059ba..ad47a1de1f0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -20084,6 +20084,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/j+k/kt7523.kt"); } + @Test + @TestMetadata("ktij24272.kt") + public void testKtij24272() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/ktij24272.kt"); + } + @Test @TestMetadata("matchers.kt") public void testMatchers() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index fce2f4b31ea..23b6d71d5d8 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -20090,6 +20090,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/j+k/kt7523.kt"); } + @Test + @TestMetadata("ktij24272.kt") + public void testKtij24272() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/ktij24272.kt"); + } + @Test @TestMetadata("matchers.kt") public void testMatchers() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCloneableSymbolProvider.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCloneableSymbolProvider.kt index 75070da6752..47860742b73 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCloneableSymbolProvider.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirCloneableSymbolProvider.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. */ @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.declarations.builder.buildRegularClass import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction -import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolNamesProvider import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolNamesProviderWithoutCallables import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl @@ -36,7 +35,7 @@ import org.jetbrains.kotlin.name.StandardClassIds class FirCloneableSymbolProvider( session: FirSession, moduleData: FirModuleData, - scopeProvider: FirScopeProvider + scopeProvider: FirScopeProvider, ) : FirSymbolProvider(session) { private val klass = buildRegularClass { resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES @@ -47,9 +46,14 @@ class FirCloneableSymbolProvider( Modality.ABSTRACT, EffectiveVisibility.Public ) + classKind = ClassKind.INTERFACE val classSymbol = FirRegularClassSymbol(StandardClassIds.Cloneable) symbol = classSymbol + superTypeRefs += buildResolvedTypeRef { + type = session.builtinTypes.anyType.type + } + declarations += buildSimpleFunction { this.moduleData = moduleData resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES @@ -57,14 +61,18 @@ class FirCloneableSymbolProvider( returnTypeRef = buildResolvedTypeRef { type = session.builtinTypes.anyType.type } + status = FirResolvedDeclarationStatusImpl( Visibilities.Protected, Modality.OPEN, - Visibilities.Protected.toEffectiveVisibility(classSymbol)) + Visibilities.Protected.toEffectiveVisibility(classSymbol) + ) + name = StandardClassIds.Callables.clone.callableName symbol = FirNamedFunctionSymbol(StandardClassIds.Callables.clone) dispatchReceiverType = this@buildRegularClass.symbol.constructType(emptyArray(), isNullable = false) } + this.scopeProvider = scopeProvider name = StandardClassIds.Cloneable.shortClassName diff --git a/compiler/testData/diagnostics/tests/j+k/ktij24272.kt b/compiler/testData/diagnostics/tests/j+k/ktij24272.kt new file mode 100644 index 00000000000..a411c994bce --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/ktij24272.kt @@ -0,0 +1,29 @@ +// FIR_IDENTICAL +// FILE: use.kt +package one + +fun getStructureElementFor() { + val container: SuperJava = if (true) { + true as Child2 + } else { + false as Child1 + } +} + +// FILE: SuperJava.java +package one; + +public class SuperJava { +} + +// FILE: Child1.java +package one; + +public class Child1 extends SuperJava implements Cloneable { +} + +// FILE: Child2.java +package one; + +public class Child2 extends SuperJava implements Cloneable { +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 64d9b456d18..ab2b17a3505 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -20090,6 +20090,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/j+k/kt7523.kt"); } + @Test + @TestMetadata("ktij24272.kt") + public void testKtij24272() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/ktij24272.kt"); + } + @Test @TestMetadata("matchers.kt") public void testMatchers() throws Exception {