[NI] Make behaviour of anonymous functions consistent with lambdas

Fix completion of anonymous functions with expression body without expected type.
Premature completion led to losing type info from outer calls.
Also report type mismatches on empty lambda expressions.

KT-34729 In progress
This commit is contained in:
Pavel Kirpichenkov
2020-01-20 13:47:43 +03:00
parent 4554f91aff
commit 3a98c84105
14 changed files with 185 additions and 13 deletions
@@ -0,0 +1,19 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
interface ILength {
val length: Int
}
class Impl(override val length: Int) : ILength
fun <T> foo(a: (Int) -> T) = 0
fun <T : ILength> bar(a: (Int) -> T) {
a(42).length
}
fun test() {
foo<String> { }
bar<Impl> { }
}
+19
View File
@@ -0,0 +1,19 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
interface ILength {
val length: Int
}
class Impl(override val length: Int) : ILength
fun <T> foo(a: (Int) -> T) = 0
fun <T : ILength> bar(a: (Int) -> T) {
a(42).length
}
fun test() {
foo<String> <!NI;TYPE_MISMATCH!>{ <!OI;TYPE_MISMATCH!><!>}<!>
bar<Impl> <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>{ <!OI;TYPE_MISMATCH!><!>}<!>
}
@@ -0,0 +1,20 @@
package
public fun </*0*/ T : ILength> bar(/*0*/ a: (kotlin.Int) -> T): kotlin.Unit
public fun </*0*/ T> foo(/*0*/ a: (kotlin.Int) -> T): kotlin.Int
public fun test(): kotlin.Unit
public interface ILength {
public abstract val length: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Impl : ILength {
public constructor Impl(/*0*/ length: kotlin.Int)
public open override /*1*/ val length: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}