From f7626d6474bff5fceba8506c37480e8918bd11cf Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 27 Jan 2020 15:39:59 +0300 Subject: [PATCH] Exclude reporting `IMPLICIT_NOTHING_AS_TYPE_PARAMETER` warning for suspend lambdas ^KT-36101 Fixed --- .../ImplicitNothingAsTypeParameterCallChecker.kt | 4 ++-- .../implicitNothingAsTypeParameter.fir.kt | 10 ++++++++++ .../typeParameters/implicitNothingAsTypeParameter.kt | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt index df7655ac009..f74bebff00e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ImplicitNothingAsTypeParameterCallChecker.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers import com.intellij.psi.PsiElement import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType -import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.resolve.calls.SPECIAL_FUNCTION_NAMES import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -44,7 +44,7 @@ object ImplicitNothingAsTypeParameterCallChecker : CallChecker { return if (resultingDescriptor.name !in SPECIAL_FUNCTION_NAMES && resolvedCall.call.typeArguments.isEmpty()) { val lambdasFromArgumentsReturnTypes = - resolvedCall.candidateDescriptor.valueParameters.filter { it.type.isFunctionType } + resolvedCall.candidateDescriptor.valueParameters.filter { it.type.isFunctionOrSuspendFunctionType } .map { it.returnType?.arguments?.last()?.type }.toSet() val unsubstitutedReturnType = resultingDescriptor.original.returnType val expectedType = context.resolutionContext.expectedType diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt index 4c3a94be300..cfe7e786efc 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.fir.kt @@ -101,3 +101,13 @@ fun test1() { fun test2() { errorCompletion.invoke(Exception("fail")) } + +fun test3() { + foo { + produceNothing() + } +} + +fun produceNothing(): Nothing = TODO() + +fun foo(block: suspend String.() -> R) = null as R diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt index 9751ede91ab..dc748041ba2 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt @@ -101,3 +101,13 @@ fun test1() { fun test2() { errorCompletion.invoke(Exception("fail")) } + +fun test3() { + foo { + produceNothing() + } +} + +fun produceNothing(): Nothing = TODO() + +fun foo(block: suspend String.() -> R) = null as R