NI: report error diagnostic about impossible to infer anonymous function's parameter
Partially fixed KT-39098
This commit is contained in:
+5
@@ -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");
|
||||
|
||||
+7
-2
@@ -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))
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun <T> select(vararg x: T) = x[0]
|
||||
fun <K> id(x: K) = x
|
||||
|
||||
fun main() {
|
||||
val x1 = select<Any?>(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<Any?>((fun (x, y) {}), fun (x: Int, y) {})
|
||||
val x5 = select<Any?>(id(fun (x, y) {}), fun (x: Int, y) {})
|
||||
val x6 = id<Any?>(fun (x) {})
|
||||
|
||||
select<Any?>(fun (x) {}, fun (x) {})
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun <T> select(vararg x: T) = x[0]
|
||||
fun <K> id(x: K) = x
|
||||
|
||||
fun main() {
|
||||
val x1 = select<Any?>(id { <!CANNOT_INFER_PARAMETER_TYPE!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, CANNOT_INFER_PARAMETER_TYPE!>y<!> -> }, { x: Int, <!CANNOT_INFER_PARAMETER_TYPE!>y<!> -> })
|
||||
val x2 = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>select<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id<!> { x, <!CANNOT_INFER_PARAMETER_TYPE!>y<!> -> }, { x: Int, <!CANNOT_INFER_PARAMETER_TYPE!>y<!> -> })
|
||||
|
||||
val x3 = select(id(fun (x, y) {}), fun (x: Int, y) {})
|
||||
|
||||
val x4 = select<Any?>((fun (<!CANNOT_INFER_PARAMETER_TYPE!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE!>y<!>) {}), fun (x: Int, <!CANNOT_INFER_PARAMETER_TYPE!>y<!>) {})
|
||||
val x5 = select<Any?>(id(fun (<!CANNOT_INFER_PARAMETER_TYPE, CANNOT_INFER_PARAMETER_TYPE!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, CANNOT_INFER_PARAMETER_TYPE!>y<!>) {}), fun (x: Int, <!CANNOT_INFER_PARAMETER_TYPE!>y<!>) {})
|
||||
val x6 = id<Any?>(fun (<!CANNOT_INFER_PARAMETER_TYPE!>x<!>) {})
|
||||
|
||||
select<Any?>(fun (<!CANNOT_INFER_PARAMETER_TYPE!>x<!>) {}, fun (<!CANNOT_INFER_PARAMETER_TYPE!>x<!>) {})
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ K> id(/*0*/ x: K): K
|
||||
public fun main(): kotlin.Unit
|
||||
public fun </*0*/ T> select(/*0*/ vararg x: T /*kotlin.Array<out T>*/): T
|
||||
@@ -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");
|
||||
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user