From a801eccf66b1ba4a636a7e3441094073a52f2e2b Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 19 May 2021 18:53:03 +0300 Subject: [PATCH] FIR: Report ARGUMENT_TYPE_MISMATCH instead of TYPE_MISMATCH for arguments --- .../coneDiagnosticToFirDiagnostic.kt | 2 +- ...entOperationInLambdaWithExpectedType.fir.kt | 2 +- .../postponedArgumentsAnalysis/basic.fir.kt | 18 +++++++++--------- .../completionOfMultipleLambdas.fir.kt | 2 +- .../conversionForDerivedGenericClass.fir.kt | 2 +- .../tests/regressions/kt30245.fir.kt | 14 +++++++------- .../conversionOnLambdaAsLastExpression.fir.kt | 4 ++-- .../suspendFunctions.fir.kt | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index da23e5f2743..b019f97d3d4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -219,7 +219,7 @@ private fun ConstraintSystemError.toDiagnostic( } argument?.let { - return FirErrors.TYPE_MISMATCH.on(it.source ?: source, lowerConeType, upperConeType) + return FirErrors.ARGUMENT_TYPE_MISMATCH.on(it.source ?: source, lowerConeType, upperConeType) } when (position) { diff --git a/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt index ad9dee88e17..ac9ddf444fe 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/assignmentOperationInLambdaWithExpectedType.fir.kt @@ -12,5 +12,5 @@ fun test(bal: Array) { val e: Unit = run { bar += 4 } - val f: Int = run { bar += 4 } + val f: Int = run { bar += 4 } } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt index 2e08d507406..37b9c746b52 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -138,8 +138,8 @@ fun main() { * K <: (C) -> Unit -> TypeVariable(_RP1) >: C * K == (B) -> Unit -> TypeVariable(_RP1) == B */ - val x17: (C) -> Unit = selectB(id { it }, id { it }, id<(B) -> Unit> { x -> x }) - val x18: (C) -> Unit = select(id { it }, { it }, id<(B) -> Unit> { x -> x }) + val x17: (C) -> Unit = selectB(id { it }, id { it }, id<(B) -> Unit> { x -> x }) + val x18: (C) -> Unit = select(id { it }, { it }, id<(B) -> Unit> { x -> x }) // Resolution of extension/non-extension functions combination val x19: String.() -> Unit = select(")!>id { this }, ")!>id(fun(x: String) {})) @@ -149,14 +149,14 @@ fun main() { select(")!>id(fun String.(x: String) {}), ")!>id(fun(x: String, y: String) {})) select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x: String -> this }) select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x -> this }) - select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x: String, y: String -> x }) + select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x: String, y: String -> x }) // Convert to extension lambda is impossible because the lambda parameter types aren't specified explicitly - select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x, y -> x }) + select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x, y -> x }) select(id(id(fun(x: String, y: String) { }), fun String.(x: String) {}), { x, y -> x }) val x26: Int.(String) -> Int = fun (x: String) = 10 // it must be error, see KT-38439 // Receiver must be specified in anonymous function declaration - val x27: Int.(String) -> Int = id(fun (x: String) = 10) - select(id Unit> {}, { x: Int, y: String -> x }) + val x27: Int.(String) -> Int = id(fun (x: String) = 10) + select(id Unit> {}, { x: Int, y: String -> x }) // Inferring lambda parameter types by partially specified parameter types of other lambdas select(id { x, y -> x.inv() + y.toByte() }, { x: Int, y -> y.toByte() }, { x, y: Number -> x.inv() }) @@ -218,7 +218,7 @@ fun main() { ")!>select({ x: Int -> TODO() }, id { x: Int, y: Number -> Any() }) ")!>select(id { x: Int -> null }, id { x: String -> "" }) ")!>select(id { x: Int -> 10 }, id { x: Int, y: Number -> TODO() }) - val x68: String.(String) -> String = select(id { x: String, y: String -> "10" }, id { x: String, y: String -> "TODO()" }) + val x68: String.(String) -> String = select(id { x: String, y: String -> "10" }, id { x: String, y: String -> "TODO()" }) // Anonymous functions val x69: (C) -> Unit = selectB({ it }, { }, id(fun (x) { x })) @@ -229,7 +229,7 @@ fun main() { val x71: String.() -> Unit = select(")!>id(fun String.() { }), ")!>id(fun(x: String) {})) val x72: String.() -> Unit = select(fun String.() { }, fun(x: String) {}) // must be error select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), fun (x, y) { x;y }) - select(id Unit>(fun (x, y) {}), { x: Int, y: String -> x }) // receiver of anonymous function must be specified explicitly - select(id Unit>(fun Int.(y) {}), { x: Int, y: String -> x }) + select(id Unit>(fun (x, y) {}), { x: Int, y: String -> x }) // receiver of anonymous function must be specified explicitly + select(id Unit>(fun Int.(y) {}), { x: Int, y: String -> x }) ")!>select(A3(), fun (x) = "", { a -> a }) } diff --git a/compiler/testData/diagnostics/tests/inference/completionOfMultipleLambdas.fir.kt b/compiler/testData/diagnostics/tests/inference/completionOfMultipleLambdas.fir.kt index 2d16bb1696d..1eecea5eea4 100644 --- a/compiler/testData/diagnostics/tests/inference/completionOfMultipleLambdas.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completionOfMultipleLambdas.fir.kt @@ -11,7 +11,7 @@ fun test() { select3( { a: A, b: A -> Unit }, { b, a -> Unit }, - { it; Unit } + { it; Unit } ) } diff --git a/compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt index 1626dac4fad..02d918d8339 100644 --- a/compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt @@ -18,5 +18,5 @@ fun test(a: A, b: B, c: C) { b.f { } c.f { } C().f { } - C.g { } + C.g { } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt index c15615a393e..80b9c12756b 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt @@ -7,8 +7,8 @@ fun id(x: K): K = x fun test() { val f00: Sample.() -> Unit = id { val a = 1 } - val f01: Sample.() -> Unit = id { s: Sample -> } - val f02: Sample.() -> Unit = id Unit> { s: Sample -> } + val f01: Sample.() -> Unit = id { s: Sample -> } + val f02: Sample.() -> Unit = id Unit> { s: Sample -> } } enum class E { VALUE } @@ -45,10 +45,10 @@ fun test1() { // to extension lambda 0 val g10: E0 = id(fun Int.(): Int = this) // oi+ ni+ val w11 = W1 { i: Int -> i } // oi- ni- - val i11: E0 = id { i: Int -> i } // o1+ ni+ + val i11: E0 = id { i: Int -> i } // o1+ ni+ val w12 = W1 { i -> i } // oi- ni- - val i12: E0 = id { i -> i } // oi- ni- - val j12 = id { i -> i } // oi- ni- + val i12: E0 = id { i -> i } // oi- ni- + val j12 = id { i -> i } // oi- ni- // yet unsupported cases - considering lambdas as extension ones unconditionally // val w13 = W1 { it } // this or it: oi- ni- @@ -84,9 +84,9 @@ fun test2() { // to extension lambda 1 val i27a: E1 = when (e) { E.VALUE -> { s -> this + s.length } } // oi+ ni+ val w28 = W2 { i: Int, s -> i + s.length } // oi- ni- - val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- + val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- val w29 = W2 { i: Int, s: String -> i + s.length } // oi- ni- - val i29: E1 = id { i: Int, s: String -> i + s.length } // oi+ ni+ + val i29: E1 = id { i: Int, s: String -> i + s.length } // oi+ ni+ // yet unsupported cases with ambiguity for the lambda conversion (commented constructors in wrappers above) // val w2a = W2 { i, s -> i + s.length } // overload oi- ni- diff --git a/compiler/testData/diagnostics/tests/samConversions/conversionOnLambdaAsLastExpression.fir.kt b/compiler/testData/diagnostics/tests/samConversions/conversionOnLambdaAsLastExpression.fir.kt index 5c8a950bbbc..d0a6a44e341 100644 --- a/compiler/testData/diagnostics/tests/samConversions/conversionOnLambdaAsLastExpression.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/conversionOnLambdaAsLastExpression.fir.kt @@ -10,8 +10,8 @@ public class A { void add(C c) {} } class B : A() { fun test(x: Any?) { - add(foo { { _ : String -> Unit } }) - add(x?.let { { _ : String -> Unit } }) + add(foo { { _ : String -> Unit } }) + add(x?.let { { _ : String -> Unit } }) } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt index ade28898909..3e542ed53d1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.fir.kt @@ -19,7 +19,7 @@ fun main() { val x1: suspend (Int) -> Unit = takeSuspend(")!>id { it }, ")!>{ x -> x }) // Here, the error should be - val x2: (Int) -> Unit = takeSuspend(")!>id { it }, "), TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) - val x3: suspend (Int) -> Unit = takeSimpleFunction(")!>id { it }, "), TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) + val x2: (Int) -> Unit = takeSuspend(")!>id { it }, ")!>{ x -> x }) + val x3: suspend (Int) -> Unit = takeSimpleFunction(")!>id { it }, ")!>{ x -> x }) val x4: (Int) -> Unit = takeSimpleFunction(id Unit> {}, ")!>{}) }