[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,6 @@
fun <T: Any> test(f: (T) -> T?) {
doFun(f.ext())
}
fun <E : Any> Function1<E, E?>.ext(): Function0<E?> = throw Exception()
fun <R : Any> doFun(f: () -> R?) = f
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Base<out T>
class ParameterizedChild<out R> : Base<R>
class Child : Base<Nothing>
fun <K> elvis(x: K?, y: K): K = TODO()
fun <K> select(x: K, y: K): K = TODO()
fun <V> myRun(f: () -> V): V = f()
fun <S> test1(a: ParameterizedChild<S>?, b: Child): Base<S> = myRun {
elvis(a, b)
}
fun <S> test2(a: S?, b: S): S = myRun {
select(a, b)
}
@@ -0,0 +1,88 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun <T> select(x: T, y: T): T = x
open class Inv<K>
class SubInv<V> : Inv<V>()
fun testSimple() {
val a0 = select(Inv<Int>(), SubInv())
a0
val a1 = select(SubInv<Int>(), Inv())
a1
}
fun testNullability() {
val n1 = select(Inv<Int?>(), SubInv())
n1
val n2 = select(SubInv<Int?>(), Inv())
n2
}
fun testNested() {
val n1 = select(Inv<Inv<Int>>(), SubInv())
n1
val n2 = select(SubInv<SubInv<Int>>(), Inv())
n2
fun <K> createInvInv(): Inv<Inv<K>> = TODO()
val n3 = select(SubInv<SubInv<Int>>(), createInvInv())
n3
}
fun testCaptured(cSub: SubInv<out Number>, cInv: Inv<out Number>) {
val c1 = select(cInv, SubInv())
c1
val c2 = select(cSub, Inv())
c2
}
fun testVariableWithBound() {
fun <K : Number> createWithNumberBound(): Inv<K> = TODO()
fun <K : Int> createWithIntBound(): Inv<K> = TODO()
val c1 = select(SubInv<Int>(), createWithNumberBound())
c1
val c2 = select(SubInv<String>(), createWithNumberBound())
c2
val c3 = select(SubInv<Double>(), createWithIntBound())
c3
}
fun testCapturedVariable() {
fun <K> createInvOut(): Inv<out K> = TODO()
fun <V> createSubInvOut(): SubInv<out V> = TODO()
fun <K> createInvIn(): Inv<in K> = TODO()
val c1 = select(SubInv<Number>(), createInvOut())
c1
val c2 = select(createSubInvOut<Number>(), createInvOut())
c2
val c3 = select(SubInv<Number>(), createInvIn())
c3
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import java.util.*
fun test(list: ArrayList<Int>, comparatorFun: (Int, Int) -> Int) {
sort(list, Comparator(comparatorFun))
}
public fun <E> sort(list: List<E>, c: Comparator<in E>) {
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>
public fun <K, V> GenericClass<Map<K, V>>.foo() {}
public fun <T> bar(t: T, ext: GenericClass<T>.() -> Unit) {}
fun test() {
bar(mapOf(2 to 3)) { foo() }
}
// from library
class Pair<out A, out B>
fun <K, V> mapOf(keyValuePair: Pair<K, V>): Map<K, V> = throw Exception()
infix fun <A, B> A.to(that: B): Pair<A, B> = throw Exception()
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>(val value: T) {
public fun <P> foo(extension: T.() -> P) {}
}
public fun <E> GenericClass<List<E>>.bar() {
foo( { listIterator() })
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import java.util.*
interface Foo
class Bar<B : Foo>(val list: MutableList<B>) {}
fun <F : Foo> test(map: MutableMap<String, Bar<F>>) {
map.getOrPut1("", { Bar(ArrayList()) })
}
fun <K, V> MutableMap<K, V>.getOrPut1(key: K, defaultValue: () -> V): V = throw Exception()
@@ -0,0 +1,21 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// Issue: KT-30300
class Inv<T>
class InvOut<T, out K>
class Sample
fun <T> select(x: T, y: T): T = x
fun <K1, V1> selectInvOut(a: InvOut<out K1, V1>, b: InvOut<out K1, V1>): InvOut<K1, V1> = TODO()
fun <K2, V2> emptyInvOut(): InvOut<K2, V2> = TODO()
fun <S> create(element: S): InvOut<Inv<S>, S> = TODO()
fun test(s: Sample, b: InvOut<Inv<*>, Any?>) {
selectInvOut(
b,
select(create(s), emptyInvOut())
)
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
open class View
fun test() {
val target = foo<View>() ?: foo() ?: run {}
}
fun <T : View> foo(): T? {
return null
}
@@ -0,0 +1,5 @@
// !WITH_NEW_INFERENCE
fun <T : Any> nullable(): T? = null
val value = nullable<Int>() ?: nullable()
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_EXPRESSION
fun test(condition: Boolean) {
val list1 =
if (condition) mutableListOf<Int>()
else emptyList()
list1
val list2 =
if (condition) mutableListOf()
else emptyList<Int>()
list2
}
fun <T> mutableListOf(): MutableList<T> = TODO()
fun <T> emptyList(): List<T> = TODO()
@@ -0,0 +1,12 @@
// !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>>() }
}
@@ -0,0 +1,17 @@
// !LANGUAGE: -NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface A
interface B : A
interface C : A
@Suppress("INVISIBLE_REFERENCE")
fun <K> select(x: K, y: K): @kotlin.internal.Exact K = x
fun foo(a: Any) {}
fun test(b: B, c: C) {
foo(
select(b, c)
)
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface A
interface B : A
interface C : A
@Suppress("INVISIBLE_REFERENCE")
fun <K> select(x: K, y: K): @kotlin.internal.Exact K = x
fun foo(a: Any) {}
fun test(b: B, c: C) {
foo(
select(b, c)
)
}
@@ -0,0 +1,178 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
val prop = mapOf(
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b"),
to("a", "b")
)
fun <A, B> to(a: A, b: B): Pair<A, B> = TODO()
fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> = TODO()
class Pair<out A, out B>
@@ -0,0 +1,10 @@
// !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>>>() }
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
// FILE: JavaTest.java
public class JavaTest {
public static Number[] createNumberArray() { return null; }
}
// FILE: test.kt
fun <K> select(x: K, y: K): K = x
fun <R> foo(f: () -> R): R = f()
fun test(n: Number) {
val a = select(foo { JavaTest.createNumberArray() }, emptyArray())
a
}
@@ -0,0 +1,30 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
// FILE: Inv2.java
public class Inv2<K, V> {}
// FILE: JavaSet.java
public class JavaSet {
public static <E> java.util.Set<E> newIdentityHashSet() { return null; }
public static <K, V> V get(Inv2<K, V> slice, K key) { return null; }
}
// FILE: test.kt
fun <K> select(x: K, y: K): K = x
fun <K, T> addElementToSlice(
slice: Inv2<K, MutableCollection<T>>,
key: K,
element: T
) {
val a = select(JavaSet.get(slice, key), JavaSet.newIdentityHashSet())
a
a.add(element)
}
@@ -0,0 +1,12 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
class Inv<T>
fun <K> select(x: K, y: K): K = x
fun <V> outToOut(x: Inv<out V>): Inv<out V> = TODO()
fun test(invOutAny: Inv<out Any>, invAny: Inv<Any>) {
val a: Inv<out Any> = select(invAny, outToOut(invOutAny))
}
@@ -0,0 +1,28 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: -NewInference
interface ISample
fun <K> elvisSimple(x: K?, y: K): K = y
@Suppress("INVISIBLE_REFERENCE")
fun <K> elvisExact(x: K?, y: K): @kotlin.internal.Exact K = y
fun <T : Number> materialize(): T? = TODO()
fun test(nullableSample: ISample, any: Any) {
elvisSimple(
nullableSample,
materialize()
)
elvisSimple(
elvisSimple(nullableSample, materialize()),
any
)
elvisSimple(
elvisExact(nullableSample, materialize()),
any
)
}
@@ -0,0 +1,39 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST
interface ISample
fun <K> elvisSimple(x: K?, y: K): K = y
@Suppress("INVISIBLE_REFERENCE")
fun <K> elvisExact(x: K?, y: K): @kotlin.internal.Exact K = y
fun <T : Number> materialize(): T? = null
fun <T> Any?.materialize(): T = null as T
fun test(nullableSample: ISample, any: Any) {
elvisSimple(
nullableSample,
materialize()
)
elvisSimple(
elvisSimple(nullableSample, materialize()),
any
)
elvisSimple(
elvisExact(nullableSample, materialize()),
any
)
val a: String? = null
val x1: String? = run {
a ?: a?.materialize()
}
val x2 = run {
a ?: a?.materialize()
}
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class In<in T>
class Out<out T>
class A
class B
fun <K> select(x: K, y: K): K = x
fun <V> genericIn(x: In<V>) {}
fun <V> genericOut(x: Out<V>) {}
fun test1(a: In<A>, b: In<B>) {
genericIn(select(a, b))
}
fun test2(a: Out<A>, b: Out<B>) {
genericOut(select(a, b))
}
@@ -0,0 +1,24 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv<T>
class A
class B
fun <K> select(x: K, y: K): K = x
fun <V> generic(x: Inv<V>) {}
fun test1(a: Inv<A>, b: Inv<B>) {
generic(select(a, b))
}
fun test2(a: Inv<*>?, b: Inv<*>) {
generic(a ?: b)
generic(if (a != null) a else b)
generic(a!!)
}
fun test3(a: Inv<out Any>, b: Inv<out Any>) {
generic(select(a, b))
}
@@ -0,0 +1,8 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun takeLong(i: Long) {}
fun test() {
takeLong(if (true) 1 else 0)
}
@@ -0,0 +1,6 @@
// !CHECK_TYPE
fun test() {
val array = arrayOf(arrayOf(1))
array checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<Array<Int>>>() }
}