From bfeb9537ee2fa2c4b1355e60ab605c03bbf934fa Mon Sep 17 00:00:00 2001 From: "victor.petukhov" Date: Fri, 24 May 2019 18:22:05 +0300 Subject: [PATCH] Exclude functional types for the warning reporting about implicitly inferred a type parameter to Nothing --- .../ImplicitNothingAsTypeParameterCallChecker.kt | 6 +++++- .../controlStructures/notAFunctionLabel_after.kt | 2 +- .../controlStructures/notAFunctionLabel_before.kt | 2 +- .../typeParameters/implicitNothingAsTypeParameter.kt | 12 ++++++++++++ 4 files changed, 19 insertions(+), 3 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 0abf56560d3..ba302f77e30 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 @@ -6,6 +6,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.diagnostics.Errors import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -37,7 +38,10 @@ object ImplicitNothingAsTypeParameterCallChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { val resultingDescriptor = resolvedCall.resultingDescriptor val inferredReturnType = resultingDescriptor.returnType - if (inferredReturnType is DeferredType) + val isBuiltinFunctionalType = + resolvedCall.resultingDescriptor.dispatchReceiverParameter?.value?.type?.isBuiltinFunctionalType == true + + if (inferredReturnType is DeferredType || isBuiltinFunctionalType) return if (resultingDescriptor.name !in SPECIAL_FUNCTION_NAMES && resolvedCall.call.typeArguments.isEmpty()) { val lambdasFromArgumentsReturnTypes = diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.kt index 01e8cb7fe8a..52d15ee4e69 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.kt @@ -52,7 +52,7 @@ fun testLoopLabelInReturn(xs: List) { fun testValLabelInReturn() { L@ val fn = { return@L } - fn() + fn() } fun testHighOrderFunctionCallLabelInReturn() { diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.kt index df9a7999554..00a174f3a88 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.kt @@ -52,7 +52,7 @@ fun testLoopLabelInReturn(xs: List) { fun testValLabelInReturn() { L@ val fn = { return@L } - fn() + fn() } fun testHighOrderFunctionCallLabelInReturn() { diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt index 2c0d0e576c6..3e7657019bf 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingAsTypeParameter.kt @@ -89,3 +89,15 @@ fun stateless( interface Worker interface RenderContext + +val emptyOrNull: List? = null +val x = emptyOrNull?.get(0) + +val errorCompletion = { e: Throwable -> throw Exception() } + +fun test1() { + errorCompletion(Exception("fail")) +} +fun test2() { + errorCompletion.invoke(Exception("fail")) +}