From 5770d19d618485210a49ed502ded4b472df4a990 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 27 Nov 2019 13:56:57 +0300 Subject: [PATCH] [FIR] Fix calculating of completion mode --- .../fir/resolve/calls/InferenceCompletion.kt | 6 +++-- .../inference/complexConstraintSystem.kt | 5 ++++ .../inference/complexConstraintSystem.txt | 24 +++++++++++++++++++ ...FirDiagnosticsWithStdlibTestGenerated.java | 18 ++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.kt create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.txt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceCompletion.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceCompletion.kt index 5e699634ea0..20c17142433 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceCompletion.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceCompletion.kt @@ -77,9 +77,11 @@ private fun Candidate.hasProperNonTrivialLowerConstraints(components: InferenceC val constructor = typeVariable.typeConstructor(context) val variableWithConstraints = csBuilder.currentStorage().notFixedTypeVariables[constructor] ?: return false val constraints = variableWithConstraints.constraints - return constraints.isNotEmpty() && constraints.all { + // TODO: support Exact annotation + // see KotlinCallCompleter:244 + return constraints.isNotEmpty() && constraints.any { !it.type.typeConstructor(context).isIntegerLiteralTypeConstructor(context) && - it.kind.isLower() && csBuilder.isProperType(it.type) + (it.kind.isLower() || it.kind.isEqual()) && csBuilder.isProperType(it.type) } } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.kt b/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.kt new file mode 100644 index 00000000000..72929c93b36 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.kt @@ -0,0 +1,5 @@ +class Inv(val x: X) + +fun test_0(list: List, b: Boolean) { + val x = list.mapNotNull { if (b) Inv(it) else null }.first().x +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.txt b/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.txt new file mode 100644 index 00000000000..55157275558 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.txt @@ -0,0 +1,24 @@ +FILE: complexConstraintSystem.kt + public final class Inv : R|kotlin/Any| { + public constructor(x: R|X|): R|Inv| { + super() + } + + public final val x: R|X| = R|/x| + public get(): R|X| + + } + public final fun test_0(list: R|kotlin/collections/List|, b: R|kotlin/Boolean|): R|kotlin/Unit| { + lval x: R|kotlin/Int| = R|/list|.R|kotlin/collections/mapNotNull||>( = mapNotNull@fun (it: R|kotlin/Int|): R|Inv?| { + when () { + R|/b| -> { + R|/Inv.Inv|(R|/it|) + } + else -> { + Null(null) + } + } + + } + ).R|kotlin/collections/first||>().R|FakeOverride| + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index f469e46b198..40393eaaefb 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -379,6 +379,24 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic } } + @TestMetadata("compiler/fir/resolve/testData/resolve/stdlib/inference") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Inference extends AbstractFirDiagnosticsWithStdlibTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/stdlib/inference"), Pattern.compile("^([^.]+)\\.kt$"), true); + } + + @TestMetadata("complexConstraintSystem.kt") + public void testComplexConstraintSystem() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/inference/complexConstraintSystem.kt"); + } + } + @TestMetadata("compiler/fir/resolve/testData/resolve/stdlib/j+k") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)