From f8ef4786478404df74bfd31f75eda56bd38bda41 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 11 Apr 2023 16:17:55 +0300 Subject: [PATCH] [FIR] Assume smartacsts on member properties from friend modules as stable ^KT-57893 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 +++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++++ .../fir/resolve/dfa/VariableStorageImpl.kt | 4 ++- .../smartCasts/smartcastInFriendModule.fir.kt | 26 +++++++++++++++++++ .../smartCasts/smartcastInFriendModule.kt | 26 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.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 a599c0c1131..c998b088c93 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 @@ -29764,6 +29764,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.kt"); } + @Test + @TestMetadata("smartcastInFriendModule.kt") + public void testSmartcastInFriendModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt"); + } + @Test @TestMetadata("smartcastOnSameFieldOfDifferentInstances.kt") public void testSmartcastOnSameFieldOfDifferentInstances() 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 1e08bea7186..c88e3125643 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 @@ -29764,6 +29764,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.kt"); } + @Test + @TestMetadata("smartcastInFriendModule.kt") + public void testSmartcastInFriendModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt"); + } + @Test @TestMetadata("smartcastOnSameFieldOfDifferentInstances.kt") public void testSmartcastOnSameFieldOfDifferentInstances() 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 1dc342b10dc..ec59ea89476 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 @@ -29764,6 +29764,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.kt"); } + @Test + @TestMetadata("smartcastInFriendModule.kt") + public void testSmartcastInFriendModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt"); + } + @Test @TestMetadata("smartcastOnSameFieldOfDifferentInstances.kt") public void testSmartcastOnSameFieldOfDifferentInstances() 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 55b580777d3..5f62ff7cb91 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 @@ -29860,6 +29860,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.kt"); } + @Test + @TestMetadata("smartcastInFriendModule.kt") + public void testSmartcastInFriendModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt"); + } + @Test @TestMetadata("smartcastOnSameFieldOfDifferentInstances.kt") public void testSmartcastOnSameFieldOfDifferentInstances() throws Exception { diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt index c65598abd78..62f7113ccf0 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorageImpl.kt @@ -176,7 +176,9 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() { val propertyModuleData = property.originalOrSelf().moduleData val currentModuleData = session.moduleData when (propertyModuleData) { - currentModuleData, in currentModuleData.dependsOnDependencies -> PropertyStability.STABLE_VALUE + currentModuleData, + in currentModuleData.friendDependencies, + in currentModuleData.dependsOnDependencies -> PropertyStability.STABLE_VALUE else -> PropertyStability.ALIEN_PUBLIC_PROPERTY } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.fir.kt new file mode 100644 index 00000000000..811ae6be59b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.fir.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-57893 +// MODULE: main +internal class A { + val x: String? = null +} + +class B { + internal val x: String? = null +} + +class C { + val x: String? = null +} + +// MODULE: test()(main) +internal fun test(a: A, b: B, c: C) { + if (a.x != null) { + a.x.length + } + if (b.x != null) { + b.x.length + } + if (c.x != null) { + c.x.length + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt new file mode 100644 index 00000000000..ad62b56f54d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-57893 +// MODULE: main +internal class A { + val x: String? = null +} + +class B { + internal val x: String? = null +} + +class C { + val x: String? = null +} + +// MODULE: test()(main) +internal fun test(a: A, b: B, c: C) { + if (a.x != null) { + a.x.length + } + if (b.x != null) { + b.x.length + } + if (c.x != null) { + c.x.length + } +} 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 e9a7fa14b73..8443c0c25c3 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 @@ -30626,6 +30626,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/smartCastOnWhen.kt"); } + @Test + @TestMetadata("smartcastInFriendModule.kt") + public void testSmartcastInFriendModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastInFriendModule.kt"); + } + @Test @TestMetadata("smartcastOnSameFieldOfDifferentInstances.kt") public void testSmartcastOnSameFieldOfDifferentInstances() throws Exception {