[FIR] Fix missing receiver type if anonymous function without label

This commit is contained in:
simon.ogorodnik
2020-04-07 23:43:42 +03:00
parent d2fd377605
commit f573719cc1
143 changed files with 249 additions and 766 deletions
@@ -7,7 +7,7 @@ fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
fun test1(a: Array<out Int>) {
val r: Array<out Int?> = bar(a)
val t = bar(a)
t checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<out Int?>>() }
t checkType { _<Array<out Int?>>() }
}
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
@@ -15,5 +15,5 @@ fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
fun test2(a: Array<out Int>) {
val r: Array<out Array<out Int?>> = foo(a)
val t = foo(a)
t checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<out Array<out Int?>>>() }
t checkType { _<Array<out Array<out Int?>>>() }
}
@@ -1,27 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VARIABLE
// FILE: A.java
public class A {
public static <T> Class<T> foo(Class<T> clazz) {
return clazz;
}
public static <T> Class<Class<T>> bar(Class<T> clazz) {
throw new Exception();
}
}
// FILE: b.kt
fun test1(clazz: Class<out Int>) {
val foo0: Class<out Int> = A.foo(clazz)
val foo1 = A.foo(clazz)
foo1 checkType { <!UNRESOLVED_REFERENCE!>_<!>< Class<out Int> >() }
foo1 checkType { <!UNRESOLVED_REFERENCE!>_<!>< Class<out Int?> >() }
}
fun tes2t(clazz: Class<in Int>) {
val foo0: Class<out Class<in Int>> = A.bar(clazz)
val foo1 = A.bar(clazz)
foo1 checkType { <!UNRESOLVED_REFERENCE!>_<!>< Class<out Class<in Int>> >() }
foo1 checkType { <!UNRESOLVED_REFERENCE!>_<!>< Class<out Class<in Int?>> >() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VARIABLE
// FILE: A.java
@@ -1,16 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T> foo(array: Array<T>): Array<T> = array
fun test1(a1: Array<out Int>) {
val b1: Array<out Int> = foo(a1)
val c1 = foo(a1)
c1 checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<out Int>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<in Int> = foo(a2)
val c2 = foo(a2)
c2 checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<in Int>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -1,16 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T> foo(a: Array<T>): Array<Array<T>> = throw Exception()
fun test1(a1: Array<out Int>) {
val b1: Array<out Array<out Int>> = foo(a1)
val c1 = foo(a1)
c1 checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<out Array<out Int>>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<out Array<in Int>> = foo(a2)
val c2 = foo(a2)
c2 checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<out Array<in Int>>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -1,14 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T> foo1(a1: Array<in T>, a2: Array<T>): T = null!!
fun test1(a1: Array<Int>, a2: Array<out Int>) {
foo1(a1, a2) checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
fun <T> foo2(a1: Array<T>, a2: Array<out T>): T = null!!
fun test2(a1: Array<in Int>, a2: Array<Int>) {
foo2(a1, a2) checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -1,9 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun <T> foo(l: MutableList<T>): MutableList<T> = l
fun test(l: MutableList<out Int>) {
val a: MutableList<out Int> = foo(l)
val b = foo(l)
b checkType { <!UNRESOLVED_REFERENCE!>_<!>< MutableList<out Int> >() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VARIABLE
@@ -7,6 +7,6 @@ class A<T> {
fun <E> A<E>.bar(): A<in E> = this
fun baz(x: A<out CharSequence>) {
x.bar() checkType { <!UNRESOLVED_REFERENCE!>_<!><A<*>>() }
x.bar().foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() } // See KT-10448
x.bar() checkType { _<A<*>>() }
x.bar().foo() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() } // See KT-10448
}
@@ -1,8 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T> foo(a: Array<T>): T = null!!
fun test(a: Array<in Int>) {
foo(a) checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -1,8 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T> foo(a: Array<T>): T = null!!
fun test(a: Array<out Int>) {
foo(a) checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -6,7 +6,7 @@ fun noCoercionLastExpressionUsedAsReturnArgument() {
42
}
a checkType { <!UNRESOLVED_REFERENCE!>_<!><() -> Int>() }
a checkType { _<() -> Int>() }
}
fun noCoercionBlockHasExplicitType() {
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
// KT-3372 Use upper bound in type argument inference
import java.util.HashSet
fun <T, C: MutableCollection<T>> Iterable<T>.toCollection(result: C) : C = throw Exception()
fun test(list: List<Int>) {
val set = list.toCollection(HashSet())
set checkType { <!UNRESOLVED_REFERENCE!>_<!><HashSet<Int>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
// KT-3372 Use upper bound in type argument inference
@@ -1,10 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> = throw Exception()
fun test(list: List<List<Int>>) {
val list1 = list.map { it.map { "$it" } }
list1 checkType { <!UNRESOLVED_REFERENCE!>_<!><List<List<String>>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
@@ -1,6 +0,0 @@
// !CHECK_TYPE
fun test() {
val array = arrayOf(arrayOf(1))
array checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<Array<Int>>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
fun test() {
@@ -9,5 +9,5 @@ fun <K> invOut(y: K?): Inv<Out<K>> = TODO()
fun <R> test(x: Inv<Out<R>>): R = TODO()
fun testNothing() {
test(invOut(null)) checkType { <!UNRESOLVED_REFERENCE!>_<!><Nothing>() }
test(invOut(null)) checkType { _<Nothing>() }
}
@@ -1,19 +0,0 @@
// !CHECK_TYPE
interface A<T>
fun <T> foo(a: A<T>, aN: A<T?>): T = throw Exception("$a $aN")
fun <T> doA(a: A<T>): T = throw Exception("$a")
fun test(a: A<Int>, aN: A<Int?>) {
val aa = doA(aN)
aa checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
val nullable = foo(aN, aN)
//T = Int?, T? = Int? => T = Int?
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
val notNullable = foo(a, aN)
//T = Int, T? = Int? => T = Int
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A<T>
@@ -15,7 +15,7 @@ fun test(out: Out<Int>, i: In<Int>, inv: A<Int>) {
// T? >: Int => T = Int
doT(1)
val r = doOut(out)
r checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
r checkType { _<Int>() }
// T? <: Int => error
<!INAPPLICABLE_CANDIDATE!>doIn<!>(i)
@@ -1,22 +0,0 @@
// !CHECK_TYPE
interface A<T>
interface Out<out T>
fun <T> foo(a: A<T>, o: Out<T?>): T = throw Exception("$a $o")
fun <T> doOut(o: Out<T?>): T = throw Exception("$o")
fun test(a: A<Int>, aN: A<Int?>, o: Out<Int?>) {
val out = doOut(o)
//T? >: Int? => T >: Int
out checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
val nullable = foo(aN, o)
//T = Int?, T? >: Int? => T = Int?
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
val notNullable = foo(a, o)
//T = Int, T? >: Int? => T = Int
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A<T>
@@ -1,22 +0,0 @@
// !CHECK_TYPE
interface A<T>
interface In<in T>
fun <T> foo(a: A<T>, i: In<T>): T = throw Exception("$a $i")
fun <T> doIn(i: In<T?>): T = throw Exception("$i")
fun test(a: A<Int>, aN: A<Int?>, i: In<Int?>) {
val _in = doIn(i)
//T? <: Int? => T <: Int?
_in checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
val notNullable = foo(a, i)
//T = Int, T? <: Int? => T = Int
notNullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
val nullable = foo(aN, i)
//T = Int?, T? <: Int? => T = Int?
nullable checkType { <!UNRESOLVED_REFERENCE!>_<!><Int?>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A<T>
@@ -11,19 +11,19 @@ class State(val p1: Double, val p2: () -> Int, val p3: String?)
fun test(s: SelectorFor<State>): Double {
val a = s { p1 }
a checkType { <!UNRESOLVED_REFERENCE!>_<!><AbstractSelector<State, Double>>() }
a checkType { _<AbstractSelector<State, Double>>() }
val b = s { p2 }
b checkType { <!UNRESOLVED_REFERENCE!>_<!><AbstractSelector<State, () -> Int>>()}
b checkType { _<AbstractSelector<State, () -> Int>>()}
val c = s { p3 }
c checkType { <!UNRESOLVED_REFERENCE!>_<!><AbstractSelector<State, String?>>() }
c checkType { _<AbstractSelector<State, String?>>() }
val d = s { }
d checkType { <!UNRESOLVED_REFERENCE!>_<!><AbstractSelector<State, Unit>>() }
d checkType { _<AbstractSelector<State, Unit>>() }
val e = s { return p1 }
e checkType { <!UNRESOLVED_REFERENCE!>_<!><AbstractSelector<State, Nothing>>() }
e checkType { _<AbstractSelector<State, Nothing>>() }
return null!!
}
@@ -10,8 +10,8 @@ class TestClass {
fun test(s: String): String {
val a = TestClass { "K" }
a checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
a checkType { _<String>() }
val b = TestClass { return s }
b checkType { <!UNRESOLVED_REFERENCE!>_<!><Nothing>() }
b checkType { _<Nothing>() }
}
@@ -8,8 +8,8 @@ object TestClass {
fun test(s: String): String {
val a = TestClass { TestClass { TestClass } }
a checkType { <!UNRESOLVED_REFERENCE!>_<!><TestClass>() }
a checkType { _<TestClass>() }
val b = TestClass { return s }
b checkType { <!UNRESOLVED_REFERENCE!>_<!><Nothing>() }
b checkType { _<Nothing>() }
}
@@ -8,7 +8,7 @@ class TestClass {
fun <T> test(value: T, test: TestClass): T {
val x = test { return value }
x checkType { <!UNRESOLVED_REFERENCE!>_<!><Nothing>() }
x checkType { _<Nothing>() }
return value
}
@@ -23,13 +23,13 @@ interface FutureCallback<E> {
fun test(cb: FutureCallback<String>) {
val a = cb { it[0] }
a checkType { <!UNRESOLVED_REFERENCE!>_<!><Future<Char>>() }
a checkType { _<Future<Char>>() }
val b = cb { it }
b checkType { <!UNRESOLVED_REFERENCE!>_<!><Future<String>>() }
b checkType { _<Future<String>>() }
val c = cb {}
c checkType { <!UNRESOLVED_REFERENCE!>_<!><Future<Unit>>() }
c checkType { _<Future<Unit>>() }
cb.let { callback ->
val d = callback { it.length }
@@ -1,16 +0,0 @@
// !WITH_NEW_INFERENCE
// !LANGUAGE: +ExpectedTypeFromCast
// !CHECK_TYPE
// Issue: KT-30405
inline fun <reified T> foo(): T {
TODO()
}
fun test() {
val fooCall = foo() as String // T in foo should be inferred to String
fooCall checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
val safeFooCall = foo() as? String
safeFooCall checkType { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !WITH_NEW_INFERENCE
// !LANGUAGE: +ExpectedTypeFromCast
// !CHECK_TYPE
@@ -13,7 +13,7 @@ fun test1(b: Boolean?) {
false -> null
null -> materialize<String>()
}
v checkType { <!UNRESOLVED_REFERENCE!>_<!><Inv<String>?>() }
v checkType { _<Inv<String>?>() }
}
fun test2() {
@@ -1,28 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// T is the immutable type
interface Builder<out T> {
fun build(): T
}
// T is the immutable type, U is the builder
interface Copyable<out T, out U : Builder<T>> {
fun builder(): U
}
fun <T : Copyable<T, U>, U : Builder<T>> T.copy(fn: U.() -> Unit): T = throw Exception()
open class Foo(val x: Int, val y: Int) : Copyable<Foo, Foo.FooBuilder> {
override fun builder(): FooBuilder = FooBuilder(x, y)
open class FooBuilder(var x: Int, var y: Int): Builder<Foo> {
override fun build(): Foo = Foo(x, y)
}
}
fun test() {
val foo1 = Foo(x = 1, y = 2)
val foo2 = foo1.copy { y = 3 } // this doesn't work
foo2 checkType { <!UNRESOLVED_REFERENCE!>_<!><Foo>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,10 +0,0 @@
// !CHECK_TYPE
//KT-4420 Type inference with type projections
class Foo<T>
fun <T> Foo<T>.bar(): T = throw Exception()
fun main() {
val f: Foo<out String> = Foo()
f.bar() checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
//KT-4420 Type inference with type projections
@@ -1,12 +0,0 @@
// !CHECK_TYPE
package g
import java.util.HashSet
fun <T, C: Collection<T>> convert(src: Collection<T>, dest: C): C = throw Exception("$src $dest")
fun test(l: List<Int>) {
//todo should be inferred
val r = convert(l, HashSet())
r checkType { <!UNRESOLVED_REFERENCE!>_<!><HashSet<Int>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
package g
@@ -9,8 +9,8 @@ public fun <T> listOf(t: T): List<T> = TODO()
fun usage(c: List<String>) {
val cn = c.ifEmpty { null }
cn checkType { <!UNRESOLVED_REFERENCE!>_<!><List<String>?>() }
cn checkType { _<List<String>?>() }
val cs = c.ifEmpty { listOf("x") }
cs checkType { <!UNRESOLVED_REFERENCE!>_<!><List<String>>() }
cs checkType { _<List<String>>() }
}