From aa96a05469664adf93209cb1b5c5c36e94f14d15 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 4 Apr 2019 16:09:26 +0300 Subject: [PATCH] [NI] Fix initial data flow info for analyzing lambdas #KT-30734 Fixed --- .../fir/FirDiagnosticsSmokeTestGenerated.java | 5 +++++ .../calls/tower/KotlinResolutionCallbacksImpl.kt | 2 +- .../diagnostics/tests/infos/SmartCasts.kt | 2 +- .../tests/nullabilityAndSmartCasts/kt30734.kt | 16 ++++++++++++++++ .../tests/nullabilityAndSmartCasts/kt30734.txt | 11 +++++++++++ .../checkers/DiagnosticsTestGenerated.java | 5 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 5 +++++ 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.txt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 0039fda0d40..e13a607b728 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -13944,6 +13944,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt"); } + @TestMetadata("kt30734.kt") + public void testKt30734() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt"); + } + @TestMetadata("kt362.kt") public void testKt362() throws Exception { runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index a644f0ac398..cdb402d2db5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -155,7 +155,7 @@ class KotlinResolutionCallbacksImpl( .replaceBindingTrace(trace) .replaceContextDependency(lambdaInfo.contextDependency) .replaceExpectedType(approximatesExpectedType) - .replaceDataFlowInfo(psiCallArgument.lambdaInitialDataFlowInfo).let { + .replaceDataFlowInfo(psiCallArgument.dataFlowInfoBeforeThisArgument).let { if (coroutineSession != null) it.replaceInferenceSession(coroutineSession) else it } diff --git a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt index 806ad2c3d81..c4c51b922d9 100644 --- a/compiler/testData/diagnostics/tests/infos/SmartCasts.kt +++ b/compiler/testData/diagnostics/tests/infos/SmartCasts.kt @@ -183,7 +183,7 @@ fun returnFunctionLiteral(a: Any?): Function0 { } fun returnFunctionLiteralExpressionBody(a: Any?): Function0 = - if (a is Int) { -> a } + if (a is Int) { -> a } else { -> 1 } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt new file mode 100644 index 00000000000..459974779ca --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE +// !LANGUAGE: +NewInference +// Issue: KT-30734 + +class Sample { + fun foo(): Boolean = true +} + +fun test(ls: Sample?) { + val filter: () -> Boolean = if (ls == null) { + { false } + } else { + { ls.foo() } // OK in OI, error in NI + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.txt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.txt new file mode 100644 index 00000000000..86146a43380 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.txt @@ -0,0 +1,11 @@ +package + +public fun test(/*0*/ ls: Sample?): kotlin.Unit + +public final class Sample { + public constructor Sample() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): 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/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 5a4a4fcafa6..982e9d64d8f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13951,6 +13951,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt"); } + @TestMetadata("kt30734.kt") + public void testKt30734() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt"); + } + @TestMetadata("kt362.kt") public void testKt362() throws Exception { runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 0e96e8e1284..c659e43ff0e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -13946,6 +13946,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt"); } + @TestMetadata("kt30734.kt") + public void testKt30734() throws Exception { + runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt30734.kt"); + } + @TestMetadata("kt362.kt") public void testKt362() throws Exception { runTest("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt362.kt");