From 2c294cba6403516dbdda4244272a7c7a6c722c7e Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Tue, 9 May 2023 16:49:09 +0200 Subject: [PATCH] [FIR] SupertypeComputationSession: fix false positive invisible reference for local object The problem is that FirAnonymousObject was ignored during getResolvedSuperTypeRefsForOutOfSessionDeclaration from SupertypeSupplier ^KT-58583 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../transformers/FirSupertypesResolution.kt | 3 +-- .../testData/diagnostics/tests/kt58583.kt | 19 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/kt58583.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 fbf874b47c4..ba0ec3b0f53 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 @@ -597,6 +597,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/kt57214.kt"); } + @Test + @TestMetadata("kt58583.kt") + public void testKt58583() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt58583.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() 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 e8e9bf6ac0e..e909a91836b 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 @@ -597,6 +597,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/kt57214.kt"); } + @Test + @TestMetadata("kt58583.kt") + public void testKt58583() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt58583.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() 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 95c183f1b22..55de1eec8c0 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 @@ -597,6 +597,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/kt57214.kt"); } + @Test + @TestMetadata("kt58583.kt") + public void testKt58583() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt58583.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() 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 24cd4be6c06..280360ddedb 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 @@ -597,6 +597,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/kt57214.kt"); } + @Test + @TestMetadata("kt58583.kt") + public void testKt58583() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt58583.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt index 31585887c15..f49cad6d677 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType import org.jetbrains.kotlin.fir.declarations.utils.isCompanion -import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.FirStatement @@ -624,7 +623,7 @@ open class SupertypeComputationSession { protected open fun getResolvedSuperTypeRefsForOutOfSessionDeclaration( classLikeDeclaration: FirClassLikeDeclaration, ): List? = when (classLikeDeclaration) { - is FirRegularClass -> classLikeDeclaration.superTypeRefs.filterIsInstance() + is FirClass -> classLikeDeclaration.superTypeRefs.filterIsInstance() is FirTypeAlias -> listOfNotNull(classLikeDeclaration.expandedTypeRef as? FirResolvedTypeRef) else -> null } diff --git a/compiler/testData/diagnostics/tests/kt58583.kt b/compiler/testData/diagnostics/tests/kt58583.kt new file mode 100644 index 00000000000..105804fcfc3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt58583.kt @@ -0,0 +1,19 @@ +// FIR_IDENTICAL + +// FILE: DialogWrapper.kt +package pkg + +open class DialogWrapper { + protected open class DialogWrapperAction +} + +// FILE: Main.kt +import pkg.DialogWrapper + +fun main() { + object: DialogWrapper() { + init { + object: DialogWrapperAction() {} + } + } +} 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 c5e1bdcf248..c4c50b5687e 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 @@ -597,6 +597,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/kt57214.kt"); } + @Test + @TestMetadata("kt58583.kt") + public void testKt58583() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt58583.kt"); + } + @Test @TestMetadata("LValueAssignment.kt") public void testLValueAssignment() throws Exception {