From af78ef77b4cd7ec9728e9b1701707be7b359ea35 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 8 Mar 2023 17:35:19 +0100 Subject: [PATCH] K2: don't accept reflective function kinds as possible lambda type #KT-56954 Fixed --- .../resolveWithStdlib/intellij/lambdaForKfunction.fir.txt | 2 +- .../testData/resolveWithStdlib/intellij/lambdaForKfunction.kt | 2 +- .../kotlin/fir/resolve/inference/PostponedArguments.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.fir.txt index 20bde2607df..7436d9782b4 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.fir.txt @@ -2,7 +2,7 @@ FILE: lambdaForKfunction.kt public final fun foo(arg: R|kotlin/reflect/KFunction0|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - R|/foo|(fun (): R|kotlin/Unit| { + R|/foo#|(fun (): R|kotlin/Unit| { } ) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.kt index 02da3fa47af..23b5885ed48 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/lambdaForKfunction.kt @@ -5,5 +5,5 @@ import kotlin.reflect.KFunction0 fun foo(arg: KFunction0) {} fun main() { - foo(fun() {}) // K1: TYPE_MISMATCH, K2: ok in compile-time & CCE at run-time + foo(fun() {}) // K1: TYPE_MISMATCH, K2: ok in compile-time & CCE at run-time } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index ad5b44f1fe5..c874b7f0e24 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -64,7 +64,7 @@ fun Candidate.preprocessLambdaArgument( if (expectedType != null) { val parameters = resolvedArgument.parameters val functionTypeKind = context.session.functionTypeService.extractSingleSpecialKindForFunction(anonymousFunction.symbol) - ?: resolvedArgument.expectedFunctionTypeKind + ?: resolvedArgument.expectedFunctionTypeKind?.nonReflectKind() ?: FunctionTypeKind.Function val lambdaType = createFunctionType( functionTypeKind,