From 82b6ecfa64bca70efbb9b8835134e6954da48c3b Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 2 Jul 2020 17:16:44 +0300 Subject: [PATCH] [FIR-TEST] Add test for KT-39075 --- .../coercionToUnitWithEarlyReturn.kt | 19 ++++++++++++++ .../coercionToUnitWithEarlyReturn.txt | 25 +++++++++++++++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 5 ++++ 4 files changed, 54 insertions(+) create mode 100644 compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt b/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt new file mode 100644 index 00000000000..cde99fc41b9 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt @@ -0,0 +1,19 @@ +// ISSUE: KT-39075 + +class A { + fun unit() {} +} + +fun foo(x: () -> Unit) {} + +fun main(x: A?) { + + val lambda = l@{ + if (x?.hashCode() == 0) return@l + + x?.unit() + } + + // lambda has a type (() -> Unit?) + foo(lambda) +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.txt b/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.txt new file mode 100644 index 00000000000..e04a089fcf3 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.txt @@ -0,0 +1,25 @@ +FILE: coercionToUnitWithEarlyReturn.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final fun unit(): R|kotlin/Unit| { + } + + } + public final fun foo(x: R|() -> kotlin/Unit|): R|kotlin/Unit| { + } + public final fun main(x: R|A?|): R|kotlin/Unit| { + lval lambda: R|() -> kotlin/Unit| = l@fun (): R|kotlin/Unit| { + when () { + ==(R|/x|?.{ $subj$.R|kotlin/Any.hashCode|() }, Int(0)) -> { + ^@l Unit + } + } + + ^ R|/x|?.{ $subj$.R|/A.unit|() } + } + + R|/foo|(R|/lambda|) + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index bfe166fb9f2..3cd57085d98 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1469,6 +1469,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.kt"); } + @TestMetadata("coercionToUnitWithEarlyReturn.kt") + public void testCoercionToUnitWithEarlyReturn() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt"); + } + @TestMetadata("definitelyNotNullIntersectionType.kt") public void testDefinitelyNotNullIntersectionType() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/definitelyNotNullIntersectionType.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index c06df9ed6ce..e64321d47b5 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1469,6 +1469,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/inference/capturedTypeForJavaTypeParameter.kt"); } + @TestMetadata("coercionToUnitWithEarlyReturn.kt") + public void testCoercionToUnitWithEarlyReturn() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/coercionToUnitWithEarlyReturn.kt"); + } + @TestMetadata("definitelyNotNullIntersectionType.kt") public void testDefinitelyNotNullIntersectionType() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/definitelyNotNullIntersectionType.kt");