diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 0cf3c6fbe18..17a6e98ec74 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -10794,6 +10794,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lambdasInTryCatch.kt"); } + @TestMetadata("notInferableParameterOfAnonymousFunction.kt") + public void testNotInferableParameterOfAnonymousFunction() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt"); + } + @TestMetadata("takingExtensibilityFromDeclarationOfAnonymousFunction.kt") public void testTakingExtensibilityFromDeclarationOfAnonymousFunction() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index 13bef2ddf2e..65fc1ec6b02 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -200,9 +200,14 @@ class DiagnosticReporterByTrackingStrategy( val parameterIndex = unknownParameterTypeDiagnostic.parameterIndex val argumentExpression = KtPsiUtil.deparenthesize(lambdaArgument.psiCallArgument.valueArgument.getArgumentExpression()) - if (argumentExpression !is KtLambdaExpression) return - val parameter = argumentExpression.valueParameters.getOrNull(parameterIndex) + val valueParameters = when (argumentExpression) { + is KtLambdaExpression -> argumentExpression.valueParameters + is KtNamedFunction -> argumentExpression.valueParameters // for anonymous functions + else -> return + } + + val parameter = valueParameters.getOrNull(parameterIndex) if (parameter != null) { trace.report(CANNOT_INFER_PARAMETER_TYPE.on(parameter)) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt new file mode 100644 index 00000000000..00bf1955a65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +fun select(vararg x: T) = x[0] +fun id(x: K) = x + +fun main() { + val x1 = select(id { x, y -> }, { x: Int, y -> }) + val x2 = select(id { x, y -> }, { x: Int, y -> }) + + val x3 = select(id(fun (x, y) {}), fun (x: Int, y) {}) + + val x4 = select((fun (x, y) {}), fun (x: Int, y) {}) + val x5 = select(id(fun (x, y) {}), fun (x: Int, y) {}) + val x6 = id(fun (x) {}) + + select(fun (x) {}, fun (x) {}) +} diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt new file mode 100644 index 00000000000..980d12bf2b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE + +fun select(vararg x: T) = x[0] +fun id(x: K) = x + +fun main() { + val x1 = select(id { x, y -> }, { x: Int, y -> }) + val x2 = select(id { x, y -> }, { x: Int, y -> }) + + val x3 = select(id(fun (x, y) {}), fun (x: Int, y) {}) + + val x4 = select((fun (x, y) {}), fun (x: Int, y) {}) + val x5 = select(id(fun (x, y) {}), fun (x: Int, y) {}) + val x6 = id(fun (x) {}) + + select(fun (x) {}, fun (x) {}) +} diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.txt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.txt new file mode 100644 index 00000000000..6eeb88a9e4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.txt @@ -0,0 +1,5 @@ +package + +public fun id(/*0*/ x: K): K +public fun main(): kotlin.Unit +public fun select(/*0*/ vararg x: T /*kotlin.Array*/): T diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 01e1d5b0f0c..49af09f6deb 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10801,6 +10801,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lambdasInTryCatch.kt"); } + @TestMetadata("notInferableParameterOfAnonymousFunction.kt") + public void testNotInferableParameterOfAnonymousFunction() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt"); + } + @TestMetadata("takingExtensibilityFromDeclarationOfAnonymousFunction.kt") public void testTakingExtensibilityFromDeclarationOfAnonymousFunction() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 1eb77dd1f0a..d92f79b0a33 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10796,6 +10796,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lambdasInTryCatch.kt"); } + @TestMetadata("notInferableParameterOfAnonymousFunction.kt") + public void testNotInferableParameterOfAnonymousFunction() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt"); + } + @TestMetadata("takingExtensibilityFromDeclarationOfAnonymousFunction.kt") public void testTakingExtensibilityFromDeclarationOfAnonymousFunction() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.kt");