[FIR] Fix inconsistent RETURN_TYPE_MISMATCH and TYPE_MISMATCH reporting on functions and properties

^KT-51203 Fixed
This commit is contained in:
Ivan Kochurkin
2022-03-17 16:34:19 +03:00
committed by teamcity
parent 4617615fd9
commit c6f52893fb
42 changed files with 82 additions and 77 deletions
@@ -12,7 +12,7 @@ fun foo(): String? {
run {
if (true) return@run
if (true) return <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>Obj()<!> // correct error, type check against return type of function "foo"
if (true) return <!RETURN_TYPE_MISMATCH!>Obj()<!> // correct error, type check against return type of function "foo"
}
run {
@@ -12,7 +12,7 @@ val a: () -> Unit = l@{
val b: () -> Unit = l@{
// Error, coercion can't be applied at this position!
if (true) return@l "hello"
if (true) return@l <!RETURN_TYPE_MISMATCH!>"hello"<!>
// However, this is OK, because here coercion is applied
"hello"
@@ -103,7 +103,7 @@ fun main() {
select(
id { x, y -> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>x<!>.inv() + <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>y<!>.toByte() },
id<(Int, Number) -> Int> { x, y -> x.inv() },
{} as (Number, Number) -> Int
<!RETURN_TYPE_MISMATCH!>{}<!> as (Number, Number) -> Int
)
// Inferring lambda parameter types by a few expected types (a few upper constraints)
@@ -7,4 +7,4 @@ class Foo<K>
fun main() {
val x = foo<Int, Foo<<!UNRESOLVED_REFERENCE!>_<!>>> { <!ARGUMENT_TYPE_MISMATCH!>it.toFloat()<!> }
}
}
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// Related issue: KT-28654
fun <K> select(): K = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>run { }<!>
fun <K> select(): K = <!RETURN_TYPE_MISMATCH!>run { }<!>
fun test() {
val x: Int = select()
@@ -14,4 +14,4 @@ fun doTheMapThing2(elements: List<CharSequence>): List<String> {
return elements.flatMap {
<!ARGUMENT_TYPE_MISMATCH!>if (it is String) listOf("Yeah") else null<!> // it's OK with `if`
}
}
}
@@ -11,14 +11,14 @@ abstract class Buggy {
}
val anotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
get() = <!RETURN_TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
val yetAnotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find({ v:Int -> v > 3 })<!> // neither here
get() = <!RETURN_TYPE_MISMATCH!>coll.find({ v:Int -> v > 3 })<!> // neither here
val extendedGetter : Int
get() {
return <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
return <!RETURN_TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
}
}
@@ -15,18 +15,18 @@ class SomeClass {
val e = E.VALUE
val withoutType: LambdaWithReceiver
get() = when (e) {
get() = <!RETURN_TYPE_MISMATCH!>when (e) {
E.VALUE -> { param ->
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>method<!>(param)
}
}
}<!>
val withExplicitType: LambdaWithReceiver
get() = when (e) {
get() = <!RETURN_TYPE_MISMATCH!>when (e) {
E.VALUE -> { param: Parameter ->
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>method<!>(param)
}
}
}<!>
}
class OtherClass {
@@ -38,8 +38,8 @@ class OtherClass {
val e2 = E.VALUE
val staticWithExplicitType: LambdaWithReceiver
get() = when (e2) {
get() = <!RETURN_TYPE_MISMATCH!>when (e2) {
E.VALUE -> { param: Parameter ->
<!UNRESOLVED_REFERENCE!>method<!>(param)
}
}
}<!>