diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index ed7131fe392..9d66a27416c 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -525,6 +525,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/kt56769.kt"); } + @Test + @TestMetadata("kt56877.kt") + public void testKt56877() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt56877.kt"); + } + @Test @TestMetadata("kt57085.kt") public void testKt57085() 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 ca6622776dc..0456a450a9b 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 @@ -525,6 +525,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/kt56769.kt"); } + @Test + @TestMetadata("kt56877.kt") + public void testKt56877() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt56877.kt"); + } + @Test @TestMetadata("kt57085.kt") public void testKt57085() 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 e0b426e14b4..da2f9ef8026 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 @@ -525,6 +525,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/kt56769.kt"); } + @Test + @TestMetadata("kt56877.kt") + public void testKt56877() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt56877.kt"); + } + @Test @TestMetadata("kt57085.kt") public void testKt57085() throws Exception { diff --git a/compiler/testData/diagnostics/tests/kt56877.fir.kt b/compiler/testData/diagnostics/tests/kt56877.fir.kt new file mode 100644 index 00000000000..f114be89e65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt56877.fir.kt @@ -0,0 +1,41 @@ +@file:OptIn(ExperimentalContracts::class) + +import kotlin.contracts.* + +class Success : Result() + +open class Result { + val someProperty = run { 10 } + + fun isSuccess1(): Boolean { + contract { + returns(true) implies (this@Result is Success) + } + return this@Result is Success + } + + fun isSuccess2(): Boolean { + contract { + // implicit type ref + // ERROR CLASS: Cannot calculate return type during full-body resolution (local class/object?) + returns(true) implies (this@Result.someProperty == 10) + } + return this@Result.someProperty == 10 + } +} + +fun Result.isSuccess3(): Boolean { + contract { + returns(true) implies (this@isSuccess3 is Success) + } + return this@isSuccess3 is Success +} + +fun Result.isSuccess4(): Boolean { + contract { + // implicit type ref + // ERROR CLASS: Cannot calculate return type during full-body resolution (local class/object?) + returns(true) implies (this@isSuccess4.someProperty == 10) + } + return this@isSuccess4.someProperty == 10 +} diff --git a/compiler/testData/diagnostics/tests/kt56877.kt b/compiler/testData/diagnostics/tests/kt56877.kt new file mode 100644 index 00000000000..f1c4c474eac --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt56877.kt @@ -0,0 +1,41 @@ +@file:OptIn(ExperimentalContracts::class) + +import kotlin.contracts.* + +class Success : Result() + +open class Result { + val someProperty = run { 10 } + + fun isSuccess1(): Boolean { + contract { + returns(true) implies (this@Result is Success) + } + return this@Result is Success + } + + fun isSuccess2(): Boolean { + contract { + // implicit type ref + // ERROR CLASS: Cannot calculate return type during full-body resolution (local class/object?) + returns(true) implies (this@Result.someProperty == 10) + } + return this@Result.someProperty == 10 + } +} + +fun Result.isSuccess3(): Boolean { + contract { + returns(true) implies (this@isSuccess3 is Success) + } + return this@isSuccess3 is Success +} + +fun Result.isSuccess4(): Boolean { + contract { + // implicit type ref + // ERROR CLASS: Cannot calculate return type during full-body resolution (local class/object?) + returns(true) implies (this@isSuccess4.someProperty == 10) + } + return this@isSuccess4.someProperty == 10 +} 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 75f2f83c574..4be9fee4e38 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 @@ -525,6 +525,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/kt56769.kt"); } + @Test + @TestMetadata("kt56877.kt") + public void testKt56877() throws Exception { + runTest("compiler/testData/diagnostics/tests/kt56877.kt"); + } + @Test @TestMetadata("kt57085.kt") public void testKt57085() throws Exception {