From 61bd3a8d037d4a62df3a4ece10f3dcf19943bf25 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 8 May 2019 02:45:24 +0300 Subject: [PATCH] [NI] Complete call if return type has proper lower or equal constraints There was a silly bug: equal constraint is actually a lower and an upper constraint, but we checked only presence of lower constraints. Test is important as here we have one equal constraint and should complete inner call `foo()` without propagating it to `bar` to avoid using `NoInfer` annotation multiple times --- .../resolve/calls/components/KotlinCallCompleter.kt | 3 ++- .../tests/deparenthesize/checkDeparenthesizedType.kt | 4 ++-- .../propagationOfNoInferAnnotation.kt | 10 ++++++++++ .../propagationOfNoInferAnnotation.txt | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 851008c6b2d..50a5599a66f 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -210,7 +210,8 @@ class KotlinCallCompleter( val constraints = variableWithConstraints.constraints return constraints.isNotEmpty() && constraints.all { !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/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.kt b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.kt index f03833ab722..8e89a8ad7f3 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.kt +++ b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.kt @@ -19,8 +19,8 @@ fun test(i: Int?) { foo(l4@ "") foo(("")) - foo(checkSubtype("")) - foo(checkSubtype("")) + foo(checkSubtype("")) + foo(checkSubtype("")) use(a, b, c, d) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt new file mode 100644 index 00000000000..31f95ce131f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun foo(): @kotlin.internal.NoInfer T = TODO() + +fun bar(k: K) {} + +fun test() { + bar(foo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt new file mode 100644 index 00000000000..91de405288e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt @@ -0,0 +1,5 @@ +package + +public fun bar(/*0*/ k: K): kotlin.Unit +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun foo(): T +public fun test(): kotlin.Unit