[FIR] Do not smartcast class delegation implemented properties
When a property is implemented via class delegation, it should be considered unstable for smart-casting. This is because it is unknown what kind of stability the underlying class delegate property has. It could be a stable property, or it could be implemented via a custom getter and unstable. ^KT-57417 Fixed
This commit is contained in:
+6
@@ -36967,6 +36967,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classDelegation.kt")
|
||||||
|
public void testClassDelegation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("doWhileWithBreak.kt")
|
@TestMetadata("doWhileWithBreak.kt")
|
||||||
public void testDoWhileWithBreak() throws Exception {
|
public void testDoWhileWithBreak() throws Exception {
|
||||||
|
|||||||
+6
@@ -36967,6 +36967,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classDelegation.kt")
|
||||||
|
public void testClassDelegation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("doWhileWithBreak.kt")
|
@TestMetadata("doWhileWithBreak.kt")
|
||||||
public void testDoWhileWithBreak() throws Exception {
|
public void testDoWhileWithBreak() throws Exception {
|
||||||
|
|||||||
+6
@@ -34635,6 +34635,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classDelegation.kt")
|
||||||
|
public void testClassDelegation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("doWhileWithBreak.kt")
|
@TestMetadata("doWhileWithBreak.kt")
|
||||||
public void testDoWhileWithBreak() throws Exception {
|
public void testDoWhileWithBreak() throws Exception {
|
||||||
|
|||||||
+6
@@ -34761,6 +34761,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classDelegation.kt")
|
||||||
|
public void testClassDelegation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("doWhileWithBreak.kt")
|
@TestMetadata("doWhileWithBreak.kt")
|
||||||
public void testDoWhileWithBreak() throws Exception {
|
public void testDoWhileWithBreak() throws Exception {
|
||||||
|
|||||||
+2
-5
@@ -7,8 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.dfa
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
@@ -18,8 +17,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
|
||||||
import org.jetbrains.kotlin.fir.originalOrSelf
|
|
||||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
@@ -173,7 +170,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
|
|||||||
val property = this.fir as? FirProperty ?: return PropertyStability.STABLE_VALUE
|
val property = this.fir as? FirProperty ?: return PropertyStability.STABLE_VALUE
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
property.delegate != null -> PropertyStability.DELEGATED_PROPERTY
|
property.delegate != null || property.isDelegated -> PropertyStability.DELEGATED_PROPERTY
|
||||||
property.isLocal -> if (property.isVal) PropertyStability.STABLE_VALUE else PropertyStability.LOCAL_VAR
|
property.isLocal -> if (property.isVal) PropertyStability.STABLE_VALUE else PropertyStability.LOCAL_VAR
|
||||||
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
||||||
property.receiverParameter != null -> PropertyStability.PROPERTY_WITH_GETTER
|
property.receiverParameter != null -> PropertyStability.PROPERTY_WITH_GETTER
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// ISSUE: KT-57417
|
||||||
|
|
||||||
|
interface HasProperty {
|
||||||
|
val property: Int?
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test(delegate: HasProperty) : HasProperty by delegate
|
||||||
|
|
||||||
|
fun test(a: Test) {
|
||||||
|
if (a.property != null) <!SMARTCAST_IMPOSSIBLE!>a.property<!> + 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// ISSUE: KT-57417
|
||||||
|
|
||||||
|
interface HasProperty {
|
||||||
|
val property: Int?
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test(delegate: HasProperty) : HasProperty by delegate
|
||||||
|
|
||||||
|
fun test(a: Test) {
|
||||||
|
if (a.property != null) <!DEBUG_INFO_SMARTCAST!>a.property<!> + 1
|
||||||
|
}
|
||||||
Generated
+6
@@ -36967,6 +36967,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classDelegation.kt")
|
||||||
|
public void testClassDelegation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("doWhileWithBreak.kt")
|
@TestMetadata("doWhileWithBreak.kt")
|
||||||
public void testDoWhileWithBreak() throws Exception {
|
public void testDoWhileWithBreak() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user