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 49ec7f23267..18672bba892 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 @@ -36967,6 +36967,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia 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 @TestMetadata("doWhileWithBreak.kt") public void testDoWhileWithBreak() 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 ac33d9f23f9..68990d48834 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 @@ -36967,6 +36967,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated 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 @TestMetadata("doWhileWithBreak.kt") public void testDoWhileWithBreak() 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 91f85bbfbc4..e6cdb4445e6 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 @@ -34635,6 +34635,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir 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 @TestMetadata("doWhileWithBreak.kt") public void testDoWhileWithBreak() 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 cfbe1730ad0..8041ddbbd3c 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 @@ -34761,6 +34761,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia 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 @TestMetadata("doWhileWithBreak.kt") public void testDoWhileWithBreak() 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 497a02d0a0a..f1a616e275d 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 @@ -7,8 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.dfa import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject import org.jetbrains.kotlin.fir.declarations.FirProperty 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.visibility 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.resolve.fullyExpandedType 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 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.isVar -> PropertyStability.MUTABLE_PROPERTY property.receiverParameter != null -> PropertyStability.PROPERTY_WITH_GETTER diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.fir.kt new file mode 100644 index 00000000000..1274772571d --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.fir.kt @@ -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) a.property + 1 +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt new file mode 100644 index 00000000000..fd62222348b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/classDelegation.kt @@ -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) a.property + 1 +} 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 95870d18c6e..1e055a12758 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 @@ -36967,6 +36967,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { 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 @TestMetadata("doWhileWithBreak.kt") public void testDoWhileWithBreak() throws Exception {