From ce4a11144d7c90f7e7b95cdcf722153e298f6b70 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Sun, 8 Nov 2020 18:17:40 +0300 Subject: [PATCH] FIR: Correctly handle nullable/flexible captured types --- .../testData/resolve/flexibleCapturedType.kt | 10 ++++++++++ .../testData/resolve/flexibleCapturedType.txt | 4 ++++ .../kotlin/fir/FirDiagnosticsTestGenerated.java | 5 +++++ .../fir/FirDiagnosticsWithLightTreeTestGenerated.java | 5 +++++ ...BodyIsNotTouchedTilContractsPhaseTestGenerated.java | 5 +++++ .../org/jetbrains/kotlin/fir/types/ConeTypeContext.kt | 3 ++- 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt b/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt new file mode 100644 index 00000000000..322705e6cdc --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt @@ -0,0 +1,10 @@ +// FILE: main.kt + +fun foo(p: Processor, s: String?) { + p.process(s) +} + +// FILE: Processor.java +public interface Processor { + boolean process(T t); +} diff --git a/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.txt b/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.txt new file mode 100644 index 00000000000..d65029f28ca --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.txt @@ -0,0 +1,4 @@ +FILE: main.kt + public final fun foo(p: R|Processor|, s: R|kotlin/String?|): R|kotlin/Unit| { + R|/p|.R|SubstitutionOverride|(R|/s|) + } 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 4f99e0a755b..9d05e59ab2c 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 @@ -183,6 +183,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/fib.kt"); } + @TestMetadata("flexibleCapturedType.kt") + public void testFlexibleCapturedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt"); + } + @TestMetadata("ft.kt") public void testFt() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/ft.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 5efdd60eaa8..3d06916a9db 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 @@ -183,6 +183,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/fib.kt"); } + @TestMetadata("flexibleCapturedType.kt") + public void testFlexibleCapturedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt"); + } + @TestMetadata("ft.kt") public void testFt() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/ft.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index 541a0b5d692..06a47258dd3 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -183,6 +183,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/fib.kt"); } + @TestMetadata("flexibleCapturedType.kt") + public void testFlexibleCapturedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/flexibleCapturedType.kt"); + } + @TestMetadata("ft.kt") public void testFt() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/ft.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index ef1f2c9b5f6..6dd2fc60822 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -168,7 +168,8 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun CapturedTypeMarker.lowerType(): KotlinTypeMarker? { require(this is ConeCapturedType) - return this.lowerType + if (!this.isMarkedNullable) return this.lowerType + return this.lowerType?.makeNullable() } override fun TypeArgumentMarker.isStarProjection(): Boolean {