From 1add296388764362bfed796bca8c9236e95f7c37 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Mon, 2 Oct 2023 15:05:49 -0500 Subject: [PATCH] [FIR] Unwrap dispatcher type when determining property stability If the modality of a property is not final, the modality of the dispatch receiver can be used to determine if the property is stable. When looking up the dispatch receiver symbol, make sure to unwrap the lower bounds of flexible types. ^KT-61735 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../fir/resolve/dfa/VariableStorageImpl.kt | 5 +++-- .../tests/properties/flexibleTypeReceiver.kt | 20 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 7 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.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 1078a288b30..e4bb17f14ba 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 @@ -26058,6 +26058,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.kt"); } + @Test + @TestMetadata("flexibleTypeReceiver.kt") + public void testFlexibleTypeReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt"); + } + @Test @TestMetadata("inferPropertyTypeFromGetter.kt") public void testInferPropertyTypeFromGetter() 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 162fcf95251..015a005828a 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 @@ -26058,6 +26058,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.kt"); } + @Test + @TestMetadata("flexibleTypeReceiver.kt") + public void testFlexibleTypeReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt"); + } + @Test @TestMetadata("inferPropertyTypeFromGetter.kt") public void testInferPropertyTypeFromGetter() 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 92ef68f7ba2..58a1ad3b391 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 @@ -26058,6 +26058,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.kt"); } + @Test + @TestMetadata("flexibleTypeReceiver.kt") + public void testFlexibleTypeReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt"); + } + @Test @TestMetadata("inferPropertyTypeFromGetter.kt") public void testInferPropertyTypeFromGetter() 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 3c5f91fac9d..09e06b617b6 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 @@ -26064,6 +26064,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.kt"); } + @Test + @TestMetadata("flexibleTypeReceiver.kt") + public void testFlexibleTypeReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt"); + } + @Test @TestMetadata("inferPropertyTypeFromGetter.kt") public void testInferPropertyTypeFromGetter() 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 7baa6efecca..f3b608e9eae 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 @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeClassLikeType +import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible import org.jetbrains.kotlin.fir.types.resolvedType import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry import org.jetbrains.kotlin.fir.utils.exceptions.withFirSymbolEntry @@ -179,8 +180,8 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() { property.modality != Modality.FINAL -> { val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null - val receiverType = (dispatchReceiver.resolvedType as? ConeClassLikeType)?.fullyExpandedType(session) ?: return null - val receiverSymbol = receiverType.lookupTag.toSymbol(session) ?: return null + val receiverType = dispatchReceiver.resolvedType.lowerBoundIfFlexible().fullyExpandedType(session) + val receiverSymbol = (receiverType as? ConeClassLikeType)?.lookupTag?.toSymbol(session) ?: return null when (val receiverFir = receiverSymbol.fir) { is FirAnonymousObject -> PropertyStability.STABLE_VALUE is FirRegularClass -> if (receiverFir.modality == Modality.FINAL) PropertyStability.STABLE_VALUE else PropertyStability.PROPERTY_WITH_GETTER diff --git a/compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt b/compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt new file mode 100644 index 00000000000..f1a6a49a272 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt @@ -0,0 +1,20 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +// FILE: WorkAction.java +public interface WorkAction { + T getParameters(); +} + +// FILE: main.kt +abstract class RunGTestJob : WorkAction { + interface Parameters { + val executable: String + } + + fun execute() { + with(parameters) { + executable = executable + } + } +} 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 48ad8aa9ce5..4175a382d7b 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 @@ -27916,6 +27916,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/properties/extensionPropertyMustHaveAccessorsOrBeAbstract.kt"); } + @Test + @TestMetadata("flexibleTypeReceiver.kt") + public void testFlexibleTypeReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/flexibleTypeReceiver.kt"); + } + @Test @TestMetadata("inferPropertyTypeFromGetter.kt") public void testInferPropertyTypeFromGetter() throws Exception {