Added diagnostic tests for inference and incorporation

This commit is contained in:
Svetlana Isakova
2015-07-01 11:59:32 +03:00
parent 086e69e132
commit b8526e7048
24 changed files with 291 additions and 17 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,5 @@
package
internal fun </*0*/ R : kotlin.Any> doFun(/*0*/ f: () -> R?): () -> R?
internal fun </*0*/ T : kotlin.Any> test(/*0*/ f: (T) -> T?): kotlin.Unit
internal fun </*0*/ E : kotlin.Any> ((E) -> E?).ext(): () -> E?
@@ -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,4 @@
package
public fun </*0*/ E> sort(/*0*/ list: kotlin.List<E>, /*1*/ c: java.util.Comparator<in E>): kotlin.Unit
internal fun test(/*0*/ list: java.util.ArrayList<kotlin.Int>, /*1*/ comparatorFun: (kotlin.Int, kotlin.Int) -> kotlin.Int): kotlin.Unit
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>
public fun <K, V> GenericClass<Map<K, V>>.foo() {}
public fun bar<T>(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()
fun <A, B> A.to(that: B): Pair<A, B> = throw Exception()
@@ -0,0 +1,21 @@
package
public fun </*0*/ T> bar(/*0*/ t: T, /*1*/ ext: GenericClass<T>.() -> kotlin.Unit): kotlin.Unit
internal fun </*0*/ K, /*1*/ V> mapOf(/*0*/ keyValuePair: Pair<K, V>): kotlin.Map<K, V>
internal fun test(): kotlin.Unit
public fun </*0*/ K, /*1*/ V> GenericClass<kotlin.Map<K, V>>.foo(): kotlin.Unit
internal fun </*0*/ A, /*1*/ B> A.to(/*0*/ that: B): Pair<A, B>
internal final class GenericClass</*0*/ out T> {
public constructor GenericClass</*0*/ out T>()
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
}
internal final class Pair</*0*/ out A, /*1*/ out B> {
public constructor Pair</*0*/ out A, /*1*/ out B>()
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
}
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>(val value: T) {
public fun foo<P>(extension: T.() -> P) {}
}
public fun <E> GenericClass<List<E>>.bar() {
foo( { listIterator() })
}
@@ -0,0 +1,12 @@
package
public fun </*0*/ E> GenericClass<kotlin.List<E>>.bar(): kotlin.Unit
internal final class GenericClass</*0*/ out T> {
public constructor GenericClass</*0*/ out T>(/*0*/ value: T)
internal final val value: T
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun </*0*/ P> foo(/*0*/ extension: T.() -> P): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -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,18 @@
package
internal fun </*0*/ F : Foo> test(/*0*/ map: kotlin.MutableMap<kotlin.String, Bar<F>>): kotlin.Unit
internal fun </*0*/ K, /*1*/ V> kotlin.MutableMap<K, V>.getOrPut1(/*0*/ key: K, /*1*/ defaultValue: () -> V): V
internal final class Bar</*0*/ B : Foo> {
public constructor Bar</*0*/ B : Foo>(/*0*/ list: kotlin.MutableList<B>)
internal final val list: kotlin.MutableList<B>
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
}
internal interface Foo {
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
}
@@ -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 { _<HashSet<Int>>() }
}
@@ -0,0 +1,4 @@
package
internal fun test(/*0*/ list: kotlin.List<kotlin.Int>): kotlin.Unit
internal fun </*0*/ T, /*1*/ C : kotlin.MutableCollection<T>> kotlin.Iterable<T>.toCollection(/*0*/ result: C): C
@@ -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 { _<List<List<String>>>() }
}
@@ -0,0 +1,4 @@
package
internal fun test(/*0*/ list: kotlin.List<kotlin.List<kotlin.Int>>): kotlin.Unit
internal fun </*0*/ T, /*1*/ R> kotlin.Collection<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
@@ -0,0 +1,8 @@
// !CHECK_TYPE
fun <T> arrayOf(vararg t : T) : Array<T> = t as Array<T>
fun test() {
val array = arrayOf(arrayOf(1))
array checkType { _<Array<Array<Int>>>() }
}
@@ -0,0 +1,4 @@
package
internal fun </*0*/ T> arrayOf(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
internal fun test(): kotlin.Unit