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 eb7c9bef79e..0f4f21b9d32 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 @@ -15140,6 +15140,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag @TestMetadata("compiler/testData/diagnostics/tests/inference/coercionToUnit") @TestDataPath("$PROJECT_ROOT") public class CoercionToUnit { + @Test + @TestMetadata("afterBareReturn.kt") + public void testAfterBareReturn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt"); + } + @Test public void testAllFilesPresentInCoercionToUnit() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/coercionToUnit"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 5cf2b3bba1a..f7e5b24f24c 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -15146,6 +15146,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti @TestMetadata("compiler/testData/diagnostics/tests/inference/coercionToUnit") @TestDataPath("$PROJECT_ROOT") public class CoercionToUnit { + @Test + @TestMetadata("afterBareReturn.kt") + public void testAfterBareReturn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt"); + } + @Test public void testAllFilesPresentInCoercionToUnit() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/coercionToUnit"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index a5a05957da9..769a49e37b6 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -15140,6 +15140,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac @TestMetadata("compiler/testData/diagnostics/tests/inference/coercionToUnit") @TestDataPath("$PROJECT_ROOT") public class CoercionToUnit { + @Test + @TestMetadata("afterBareReturn.kt") + public void testAfterBareReturn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt"); + } + @Test public void testAllFilesPresentInCoercionToUnit() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/coercionToUnit"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt new file mode 100644 index 00000000000..974ddc2e21f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.fir.kt @@ -0,0 +1,41 @@ +interface I +open class C + +fun completed(): String = "..." + +fun incomplete(): T = null!! + +fun incompatibleI(): T = null!! +fun incompatibleC(): T = null!! + +val p = false + +fun expectUnit(x: Unit) = x + +fun test1() = run { + if (p) return@run + completed() // ok, not returned +} + +fun test2() = run { + if (p) return@run + incomplete() // ? either uninferred T or Unit +} + +fun test3() = run { + if (p) return@run + incompatibleI() // ? either uninferred T or error (Unit run { + if (p) return@run + incompatibleC() // ? either uninferred T or error (Unit test1()) + expectUnit(test2()) + expectUnit(test3()) + expectUnit(test4()) +} diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt new file mode 100644 index 00000000000..70a0c2fb361 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt @@ -0,0 +1,41 @@ +interface I +open class C + +fun completed(): String = "..." + +fun incomplete(): T = null!! + +fun incompatibleI(): T = null!! +fun incompatibleC(): T = null!! + +val p = false + +fun expectUnit(x: Unit) = x + +fun test1() = run { + if (p) return@run + completed() // ok, not returned +} + +fun test2() = run { + if (p) return@run + incomplete() // ? either uninferred T or Unit +} + +fun test3() = run { + if (p) return@run + incompatibleI() // ? either uninferred T or error (Unit run { + if (p) return@run + incompatibleC() // ? either uninferred T or error (Unit incompatibleC(): T +public fun incompatibleI(): T +public fun incomplete(): T +public fun main(): kotlin.Unit +public fun test1(): kotlin.Unit +public fun test2(): kotlin.Unit +public fun test3(): kotlin.Unit +public fun test4(): kotlin.Unit + +public open class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface I { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 5400a975e0d..e9510f43d39 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 @@ -15146,6 +15146,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { @TestMetadata("compiler/testData/diagnostics/tests/inference/coercionToUnit") @TestDataPath("$PROJECT_ROOT") public class CoercionToUnit { + @Test + @TestMetadata("afterBareReturn.kt") + public void testAfterBareReturn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/afterBareReturn.kt"); + } + @Test public void testAllFilesPresentInCoercionToUnit() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/coercionToUnit"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);