diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt index c62a3414dd1..2ff9cf11f3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilderImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.calls.inference import org.jetbrains.kotlin.builtins.createFunctionType +import org.jetbrains.kotlin.builtins.isBuiltinExtensionFunctionalType import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.builtins.isSuspendFunctionType import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor @@ -435,7 +436,7 @@ internal fun createTypeForFunctionPlaceholder( val functionPlaceholderTypeConstructor = functionPlaceholder.constructor as FunctionPlaceholderTypeConstructor - val isExtension = expectedType.isExtensionFunctionType + val isExtension = expectedType.isBuiltinExtensionFunctionalType val newArgumentTypes = if (!functionPlaceholderTypeConstructor.hasDeclaredArguments) { val typeParamSize = expectedType.constructor.parameters.size // the first parameter is receiver (if present), the last one is return type, diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.kt new file mode 100644 index 00000000000..30b51cf9f36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun withS(x: T, sfn: suspend T.() -> Unit) = x + +val test1 = withS(100) {} + +fun test2(x: TT) = withS(x) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.txt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.txt new file mode 100644 index 00000000000..846bfc203cf --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.txt @@ -0,0 +1,5 @@ +package + +public val test1: kotlin.Int +public fun test2(/*0*/ x: TT): TT +public fun withS(/*0*/ x: T, /*1*/ sfn: suspend T.() -> kotlin.Unit): T diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.kt new file mode 100644 index 00000000000..6df1d160a2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun withS2(x: T1, sfn1: suspend T1.() -> T2, sfn2: suspend T2.() -> Unit): T2 = null!! + +val test1 = withS2(100, { toLong().toString() }, { length }) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.txt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.txt new file mode 100644 index 00000000000..30ce0b1cb4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.txt @@ -0,0 +1,4 @@ +package + +public val test1: kotlin.String +public fun withS2(/*0*/ x: T1, /*1*/ sfn1: suspend T1.() -> T2, /*2*/ sfn2: suspend T2.() -> kotlin.Unit): T2 diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 5fc9d8f9360..49f51192d3b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -4431,6 +4431,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("inference3.kt") + public void testInference3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference3.kt"); + doTest(fileName); + } + + @TestMetadata("inference4.kt") + public void testInference4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/inference4.kt"); + doTest(fileName); + } + @TestMetadata("lambdaInOverriddenValInitializer.kt") public void testLambdaInOverriddenValInitializer() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/lambdaInOverriddenValInitializer.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt index 241197bf88d..9094cdb98f9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt @@ -87,9 +87,12 @@ fun isBuiltinFunctionClass(classId: ClassId): Boolean { } val KotlinType.isNonExtensionFunctionType: Boolean - get() = isBuiltinFunctionalType && !isTypeAnnotatedWithExtensionFunctionType + get() = isFunctionType && !isTypeAnnotatedWithExtensionFunctionType val KotlinType.isExtensionFunctionType: Boolean + get() = isFunctionType && isTypeAnnotatedWithExtensionFunctionType + +val KotlinType.isBuiltinExtensionFunctionalType: Boolean get() = isBuiltinFunctionalType && isTypeAnnotatedWithExtensionFunctionType private val KotlinType.isTypeAnnotatedWithExtensionFunctionType: Boolean @@ -137,7 +140,7 @@ fun KotlinType.getReturnTypeFromFunctionType(): KotlinType { fun KotlinType.getValueParameterTypesFromFunctionType(): List { assert(isBuiltinFunctionalType) { "Not a function type: ${this}" } val arguments = arguments - val first = if (isExtensionFunctionType) 1 else 0 + val first = if (isBuiltinExtensionFunctionalType) 1 else 0 val last = arguments.size - 1 assert(first <= last) { "Not an exact function type: ${this}" } return arguments.subList(first, last)