[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
This commit is contained in:
Brian Norman
2023-10-02 15:05:49 -05:00
committed by Space Team
parent 87904fd766
commit 1add296388
7 changed files with 53 additions and 2 deletions
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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
@@ -0,0 +1,20 @@
// FIR_IDENTICAL
// WITH_STDLIB
// FILE: WorkAction.java
public interface WorkAction<T> {
T getParameters();
}
// FILE: main.kt
abstract class RunGTestJob : WorkAction<RunGTestJob.Parameters> {
interface Parameters {
val executable: String
}
fun execute() {
with(parameters) {
<!VAL_REASSIGNMENT!>executable<!> = executable
}
}
}
@@ -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 {