[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun <T: Any> fooT22() : T? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun foo1() {
|
||||
fooT22()
|
||||
}
|
||||
|
||||
val n : Nothing = null.sure()
|
||||
|
||||
fun <T : Any> T?.sure() : T = this!!
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package f
|
||||
|
||||
fun <T> g(i: Int, a: Any): List<T> {throw Exception()}
|
||||
fun <T> g(a: Any, i: Int): Collection<T> {throw Exception()}
|
||||
|
||||
fun <T> test() {
|
||||
val c: List<T> = <!AMBIGUITY!>g<!>(1, 1)
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package f
|
||||
|
||||
fun <R> h(i: Int, a: Any, r: R, f: (Boolean) -> Int) = 1
|
||||
fun <R> h(a: Any, i: Int, r: R, f: (Boolean) -> Int) = 1
|
||||
|
||||
fun test() = <!AMBIGUITY!>h<!>(1, 1, 1, { b -> 42 })
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package f
|
||||
|
||||
fun <T> f(i: Int, c: Collection<T>): List<T> {throw Exception()}
|
||||
fun <T> f(a: Any, l: List<T>): Collection<T> {throw Exception()}
|
||||
|
||||
fun <T> test(l: List<T>) {
|
||||
<!AMBIGUITY!>f<!>(1, emptyList())
|
||||
}
|
||||
|
||||
fun <T> emptyList(): List<T> {throw Exception()}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package f
|
||||
|
||||
fun <T> f(i: Int, t: T, c: MutableCollection<T>) {}
|
||||
fun <T> f(a: Any, t: T, l: MutableList<T>) {}
|
||||
|
||||
fun test(l: List<Int>) {
|
||||
<!INAPPLICABLE_CANDIDATE!>f<!>(1, "", l)
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
|
||||
package f
|
||||
|
||||
fun <R> h(f: (Boolean) -> R) = 1
|
||||
fun <R> h(f: (String) -> R) = 2
|
||||
|
||||
fun test() = <!AMBIGUITY!>h<!>{ i -> getAnswer() }
|
||||
|
||||
fun getAnswer() = 42
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
public class A<T> {
|
||||
public A<? super T> getSuperA() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun <T : Any> foo(x: T?, func: (T) -> T?) {}
|
||||
|
||||
fun test(a: A<*>) {
|
||||
foo(a) { it.superA }
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
|
||||
fun <T> Array<out T>.intersect(other: Iterable<T>) {
|
||||
val set = toMutableSet()
|
||||
set.retainAll(other)
|
||||
}
|
||||
|
||||
fun <X> Array<out X>.toMutableSet(): MutableSet<X> = TODO()
|
||||
fun <Y> MutableCollection<in Y>.retainAll(elements: Iterable<Y>) {}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
|
||||
|
||||
fun test1(a: Array<in Int>) {
|
||||
val r: Array<in Int?> = <!INAPPLICABLE_CANDIDATE!>bar<!>(a)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(a)
|
||||
}
|
||||
|
||||
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
|
||||
|
||||
fun test2(a: Array<in Int>) {
|
||||
val r: Array<out Array<in Int?>> = <!INAPPLICABLE_CANDIDATE!>foo<!>(a)
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(a)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
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?>>() }
|
||||
}
|
||||
|
||||
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?>>>() }
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !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?>> >() }
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T : Any> Array<T?>.filterNotNull(): List<T> = throw Exception()
|
||||
|
||||
fun test1(a: Array<out Int?>) {
|
||||
val list = a.<!INAPPLICABLE_CANDIDATE!>filterNotNull<!>()
|
||||
list <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><List<Int>>() }
|
||||
}
|
||||
|
||||
fun test2(vararg a: Int?) {
|
||||
val list = a.<!INAPPLICABLE_CANDIDATE!>filterNotNull<!>()
|
||||
list <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><List<Int>>() }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun <V, R, M : MutableMap<in R, out V>> mapKeysTo(destination: M): Inv3<R, V, M> {
|
||||
val foo = associateByTo(destination)
|
||||
|
||||
return foo
|
||||
}
|
||||
|
||||
fun < Y, Z, T : MutableMap<in Y, out Z>> associateByTo(destination: T): Inv3<Y, Z, T> = TODO()
|
||||
|
||||
interface Inv3<A, B, C>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface Inv<T>
|
||||
|
||||
fun <Y: X, X : Inv<out String>> foo(x: X, y: Y) {
|
||||
val rX = <!INAPPLICABLE_CANDIDATE!>bar<!>(x)
|
||||
rX.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
val rY = <!INAPPLICABLE_CANDIDATE!>bar<!>(y)
|
||||
rY.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun <Y> bar(l: Inv<Y>): Y = TODO()
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun <T> foo(array: Array<Array<T>>): Array<Array<T>> = array
|
||||
|
||||
fun test(array: Array<Array<out Int>>) {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(array)
|
||||
|
||||
val f: Array<out Array<out Int>> = <!INAPPLICABLE_CANDIDATE!>foo<!>(array)
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !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>>() }
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// !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>>>() }
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !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?>() }
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
typealias MyString = String
|
||||
|
||||
fun test(k: KClass<out MyString>) {
|
||||
k::class.java
|
||||
}
|
||||
|
||||
@Suppress("UPPER_BOUND_VIOLATED")
|
||||
public val <T> KClass<T>.java: Class<T> get() = TODO()
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun takeCovArray(a: Array<out Number>) {}
|
||||
fun takeInArray(a: Array<in Number>) {}
|
||||
|
||||
fun <T> foo(): Array<out T> = TODO()
|
||||
fun <T> bar(): Array<in T> = TODO()
|
||||
|
||||
fun <X> id(x: X): X = x
|
||||
fun <Z> arrayInId(z: Array<in Z>): Array<in Z> = z
|
||||
fun <Z> arrayOutId(z: Array<out Z>): Array<out Z> = z
|
||||
|
||||
fun test() {
|
||||
takeCovArray(foo())
|
||||
takeInArray(bar())
|
||||
|
||||
takeCovArray(id(foo()))
|
||||
takeInArray(id(bar()))
|
||||
|
||||
takeCovArray(arrayOutId(foo()))
|
||||
takeInArray(arrayInId(bar()))
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
fun <T> foo(a1: Array<T>, a2: Array<out T>): T = null!!
|
||||
|
||||
fun test(a1: Array<in Int>, a2: Array<Int>) {
|
||||
|
||||
val c: Int = foo(a1, a2)
|
||||
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv1<T>
|
||||
|
||||
operator fun <T> Inv1<T>.invoke(action: T.() -> Unit) {}
|
||||
|
||||
fun test(inv: Inv1<out Number>) {
|
||||
inv { }
|
||||
inv.invoke { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface CollectorMock<A, R>
|
||||
|
||||
interface StreamMock {
|
||||
fun <R, A> collect(collector: CollectorMock<A, R>): R
|
||||
}
|
||||
|
||||
fun <T> accept(s: T) {}
|
||||
fun ofK(t: String): StreamMock = TODO()
|
||||
fun <T> toSetK(): CollectorMock<*, T> = TODO()
|
||||
|
||||
class KotlinCollectionUser1 {
|
||||
fun use() {
|
||||
accept(ofK("").collect(toSetK<String>()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !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> >() }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun <T> Array<T>.foo() {}
|
||||
|
||||
fun test(array: Array<out Int>) {
|
||||
array.foo()
|
||||
array.<!INAPPLICABLE_CANDIDATE!>foo<!><out Int>()
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
class A<T> {
|
||||
fun foo(): T = null!!
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class A<T>
|
||||
class B<T>
|
||||
|
||||
fun <E> foo(b: B<in A<E>>) {}
|
||||
fun <E> baz(b: B<out A<E>>) {}
|
||||
|
||||
// See KT-13950
|
||||
fun bar(b: B<in A<out Number>>, bOut: B<out A<out Number>>, bOut2: B<out A<Number>>) {
|
||||
foo(b)
|
||||
foo<Number>(b)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>baz<!>(bOut)
|
||||
<!INAPPLICABLE_CANDIDATE!>baz<!><Number>(bOut)
|
||||
|
||||
baz(bOut2)
|
||||
baz<Number>(bOut2)
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.fir.kt
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
class Bar
|
||||
|
||||
fun Bar.foo() = 42
|
||||
|
||||
object MyObject {
|
||||
fun foo(bar: Bar) = bar.foo()
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// !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?>() }
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// !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>() }
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
open class Inv<T>(val value: String)
|
||||
|
||||
fun <T : Inv<*>?, F: Inv<out Any>?, G : Inv<*>> test1(t: T, f: F, g: G?) {
|
||||
if (t != null && f != null && g != null) {
|
||||
t.value
|
||||
f.value
|
||||
g.value
|
||||
}
|
||||
}
|
||||
|
||||
// Actually, this behavior is very questional as capturing shouldn't be performed deeper than for 1 level
|
||||
// But we preserve behavior of old inference here for now
|
||||
fun <T : K, K : Inv<*>?> test2(t: T) {
|
||||
if (t != null) {
|
||||
t.value
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Inv<K>?, K : Inv<*>?> test3(t: T) {
|
||||
if (t != null) {
|
||||
t.value
|
||||
}
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// See KT-14453
|
||||
val <T : Any> KClass1<T>.primaryConstructor: KFunction1<T>? get() = null!!
|
||||
|
||||
interface KClass1<F : Any>
|
||||
interface KFunction1<out R>
|
||||
fun f(type: KClass1<*>): KFunction1<Any>? =
|
||||
// What happens here:
|
||||
// 1. Create captured type for type argument T (it's built upon star-projection from `KClass<*>` that's argument is <: Any)
|
||||
// 2. Approximate resulting descriptor, now it 'KClass1<*>.primaryConstructor: KFunction1<*>'
|
||||
// Note that star-projection in 'KFunction1<*>' is obtained from KClass and its `projectionType` is Any (not-nullable).
|
||||
// Of course that situation is already strange
|
||||
// 3. When checking subtyping after call completion we get that 'KFunction1<*>' is not a subtype of 'KFunction1<Any>' in new type checker.
|
||||
// The answer is correct, but this old type checker used `projectionType` for this and it was resulting in KFunction1<*> <: KFunction1<Any>
|
||||
//
|
||||
// So to fix the issue we use 'out starProjectionType' instead of star-projection itself in approximation
|
||||
// Note that in new inference there should be no approximation for IN-position types (they must remain captured)
|
||||
type.primaryConstructor
|
||||
compiler/testData/diagnostics/tests/inference/capturedTypes/topLevelCapturingInsideReturnType.fir.kt
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv2<T, K>
|
||||
|
||||
fun <K> createInv(): Inv2<*, K> = TODO()
|
||||
|
||||
fun <T> foo(i: Inv2<T, String>) {}
|
||||
|
||||
fun foo() {
|
||||
foo(createInv())
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun fail1(c: suspend () -> Unit) {}
|
||||
|
||||
fun fail2(c: () -> Unit) {}
|
||||
|
||||
fun success1(c: suspend () -> Unit) {}
|
||||
|
||||
fun test1() {
|
||||
fail1(fun () {})
|
||||
fun fail2(c: suspend () -> Unit) {}
|
||||
fail2(fun () {})
|
||||
fun success1(c: () -> Unit) {}
|
||||
success1(fun() {})
|
||||
}
|
||||
|
||||
suspend fun fail3(c: suspend () -> Unit) {}
|
||||
|
||||
suspend fun fail4(c: () -> Unit) {}
|
||||
|
||||
suspend fun success2(c: suspend () -> Unit) {}
|
||||
|
||||
suspend fun test2() {
|
||||
fail3(fun () {})
|
||||
fun fail4(c: suspend () -> Unit) {}
|
||||
fail4(fun () {})
|
||||
fun success2(c: () -> Unit) {}
|
||||
success2(fun() {})
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Obj
|
||||
|
||||
fun foo(): String? {
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
if (true) Obj()
|
||||
}
|
||||
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
if (true) return Obj() // correct error, type check against return type of function "foo"
|
||||
}
|
||||
|
||||
run {
|
||||
if (true)
|
||||
return@run
|
||||
else
|
||||
if (true) 42
|
||||
}
|
||||
|
||||
run {
|
||||
if (true)
|
||||
42
|
||||
else
|
||||
if (true) 42
|
||||
}
|
||||
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun coerceToUnit(f: () -> Unit) {}
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <K> builder(block: Inv<K>.() -> Unit): K = TODO()
|
||||
|
||||
fun test() {
|
||||
coerceToUnit {
|
||||
builder {}
|
||||
}
|
||||
}
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
fun <T> materialize(): T = TODO()
|
||||
|
||||
val a: () -> Unit = l@{
|
||||
// Expected type 'Unit' is used here for inference
|
||||
if (true) return@l materialize()
|
||||
|
||||
// Expected type here is Unit, but it also implies coercion,
|
||||
// so we can end lambda body with statement
|
||||
if (true) 42
|
||||
}
|
||||
|
||||
val b: () -> Unit = l@{
|
||||
// Error, coercion can't be applied at this position!
|
||||
if (true) return@l "hello"
|
||||
|
||||
// However, this is OK, because here coercion is applied
|
||||
"hello"
|
||||
}
|
||||
|
||||
val c: () -> Unit = {
|
||||
// Interesting enough, for such expessions we use expected type Unit
|
||||
// (compare that with the previous case, where we didn't used expected type Unit for "hello")
|
||||
materialize()
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
fun <T : Number> materializeNumber(): T = TODO()
|
||||
|
||||
fun a(): Unit = run {
|
||||
materializeNumber()
|
||||
}
|
||||
|
||||
fun b(): Unit = run {
|
||||
run {
|
||||
materializeNumber()
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExplicitTypeArgument.fir.kt
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
val f = myRun<Unit> {
|
||||
123
|
||||
}
|
||||
}
|
||||
|
||||
fun <R> myRun(block: () -> R): R = block()
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
fun <T> materialize(): T = TODO()
|
||||
|
||||
fun implicitCoercion() {
|
||||
val a = {
|
||||
// Block is implicitly Unit-coerced, so it is allowed to place statement at the end of lambda
|
||||
if (true) 42
|
||||
}
|
||||
|
||||
val b = l@{
|
||||
return@l
|
||||
}
|
||||
|
||||
val c = l@{
|
||||
// Error: block doesn't have an expected type, so call can't be inferred!
|
||||
return@l materialize()
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/coercionToUnit/indirectCoercionWithExpectedType.fir.kt
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
fun <T> materialize(): T = TODO()
|
||||
|
||||
fun a(): Unit = run {
|
||||
run {
|
||||
// Ok, block is coerced, because it has (indirectly) Unit-expected type
|
||||
"hello"
|
||||
}
|
||||
}
|
||||
|
||||
fun b(): Unit = run {
|
||||
// Ok, expected type is applied
|
||||
materialize()
|
||||
}
|
||||
|
||||
fun c(): Unit = run {
|
||||
run {
|
||||
// Attention!
|
||||
// In OI expected type 'Unit' isn't applied here because of implementation quirks (note that OI still applies Unit in case 'e')
|
||||
// In NI, it is applied and call is correctly inferred, which is consistent with the previous case
|
||||
materialize()
|
||||
}
|
||||
}
|
||||
|
||||
fun d(): Unit = run outer@{
|
||||
run inner@{
|
||||
return@inner materialize()
|
||||
}
|
||||
}
|
||||
|
||||
fun e(): Unit = run outer@{
|
||||
run inner@{
|
||||
return@outer materialize()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// ISSUE: KT-30242
|
||||
|
||||
class A
|
||||
|
||||
fun println(s: String = "") {}
|
||||
|
||||
fun foo(f: () -> Any) {}
|
||||
|
||||
fun test1(b: Boolean) {
|
||||
foo {
|
||||
if (b) {
|
||||
println("meh")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(b: Boolean) {
|
||||
foo {
|
||||
when {
|
||||
b -> println("meh")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(b: Boolean) {
|
||||
foo {
|
||||
if (b) {
|
||||
return@foo A()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(b: Boolean) {
|
||||
foo {
|
||||
if (b) {
|
||||
return@foo println("meh")
|
||||
}
|
||||
|
||||
if (b) {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(block: () -> String) {}
|
||||
|
||||
fun test_5(b: Boolean) {
|
||||
bar {
|
||||
if (b) {
|
||||
println("meh")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test_6(b: Boolean) {
|
||||
foo {
|
||||
if (b) {
|
||||
return@foo Unit
|
||||
}
|
||||
if (b) {}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun noCoercionLastExpressionUsedAsReturnArgument() {
|
||||
val a = {
|
||||
42
|
||||
}
|
||||
|
||||
a checkType { <!UNRESOLVED_REFERENCE!>_<!><() -> Int>() }
|
||||
}
|
||||
|
||||
fun noCoercionBlockHasExplicitType() {
|
||||
val b: () -> Int = {
|
||||
if (true) 42
|
||||
}
|
||||
}
|
||||
|
||||
fun noCoercionBlockHasExplicitReturn() {
|
||||
val c = l@{
|
||||
if (true) return@l 42
|
||||
|
||||
if (true) 239
|
||||
}
|
||||
}
|
||||
|
||||
fun noCoercionInExpressionBody(): Unit = "hello"
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Obj
|
||||
|
||||
fun foo(): String? {
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
run {
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
|
||||
}
|
||||
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null // OK, no error
|
||||
}
|
||||
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
run {
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
|
||||
}
|
||||
}
|
||||
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
run nestedRun@{
|
||||
if (true) return@nestedRun
|
||||
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null // OK, additional empty labeled return helps
|
||||
}
|
||||
|
||||
if (true) {
|
||||
Obj()
|
||||
} else
|
||||
if (true) return null // OK, no error
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
+6
@@ -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
|
||||
+20
@@ -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)
|
||||
}
|
||||
+88
@@ -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
|
||||
}
|
||||
+11
@@ -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>) {
|
||||
}
|
||||
+17
@@ -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()
|
||||
|
||||
Vendored
+9
@@ -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() })
|
||||
}
|
||||
Vendored
+13
@@ -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()
|
||||
+12
@@ -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>>() }
|
||||
}
|
||||
+17
@@ -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)
|
||||
)
|
||||
}
|
||||
+17
@@ -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)
|
||||
)
|
||||
}
|
||||
+178
@@ -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>
|
||||
+10
@@ -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>>>() }
|
||||
}
|
||||
Vendored
+20
@@ -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
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/commonSystem/nonFixedVariableInsideFlexibleType.fir.kt
Vendored
+30
@@ -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)
|
||||
}
|
||||
Vendored
+12
@@ -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))
|
||||
}
|
||||
+28
@@ -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
|
||||
)
|
||||
}
|
||||
+39
@@ -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()
|
||||
}
|
||||
}
|
||||
+20
@@ -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))
|
||||
}
|
||||
Vendored
+24
@@ -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))
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun takeLong(i: Long) {}
|
||||
|
||||
fun test() {
|
||||
takeLong(if (true) 1 else 0)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun test() {
|
||||
val array = arrayOf(arrayOf(1))
|
||||
array checkType { <!UNRESOLVED_REFERENCE!>_<!><Array<Array<Int>>>() }
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
package d
|
||||
|
||||
fun <T: Any> joinT(x: Int, vararg a: T): T? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun <T: Any> joinT(x: Comparable<*>, y: T): T? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x2 = <!INAPPLICABLE_CANDIDATE!>joinT<!>(Unit, "2")
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><String?>(x2)
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package conflictingSubstitutions
|
||||
//+JDK
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun <R> elemAndList(r: R, t: MutableList<R>): R = r
|
||||
fun <R> R.elemAndListWithReceiver(r: R, t: MutableList<R>): R = r
|
||||
|
||||
fun test() {
|
||||
val s = elemAndList(11, list("72"))
|
||||
|
||||
val u = 11.elemAndListWithReceiver(4, list("7"))
|
||||
}
|
||||
|
||||
fun <T> list(value: T) : ArrayList<T> {
|
||||
val list = ArrayList<T>()
|
||||
list.add(value)
|
||||
return list
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Out<out T>
|
||||
class In<in T>
|
||||
class Inv<T>
|
||||
|
||||
fun <R> choose1(c: Out<Out<R>>) {}
|
||||
fun <R> choose2(c: In<In<R>>) {}
|
||||
fun <R> choose3(c: Inv<Inv<R>>) {}
|
||||
|
||||
fun f(o: Out<Out<*>>, i: In<In<*>>, inv: Inv<Inv<*>>) {
|
||||
choose1(o)
|
||||
choose2(i)
|
||||
<!INAPPLICABLE_CANDIDATE!>choose3<!>(inv)
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package c
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!INAPPLICABLE_CANDIDATE!>mapTo<!>(IntArray(size), {<!UNRESOLVED_REFERENCE!>it<!>})
|
||||
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size), {it})
|
||||
|
||||
public fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(result: C, transform : (T) -> R) : C =
|
||||
throw Exception("$result $transform")
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
class Inv<T>(val x: T?)
|
||||
|
||||
fun <K> create(y: K) = Inv(y)
|
||||
fun <K> createPrivate(y: K) = Inv(y)
|
||||
|
||||
fun takeInvInt(i: Inv<Int>) {}
|
||||
|
||||
fun <S> test(i: Int, s: S) {
|
||||
val a = Inv(s)
|
||||
|
||||
a
|
||||
|
||||
val b = create(i)
|
||||
|
||||
b
|
||||
|
||||
val c = createPrivate(i)
|
||||
|
||||
c
|
||||
|
||||
takeInvInt(create(i))
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Parent
|
||||
interface Inv<T>
|
||||
|
||||
object Child : Parent
|
||||
|
||||
fun <K : Parent> wrapper(): Inv<K> = TODO()
|
||||
fun <T : Parent> consume(wrapper: Inv<T>) {}
|
||||
|
||||
fun <S> select(x: S, y: S): S = x
|
||||
|
||||
fun error(f: Inv<out Parent>, w: Inv<Child>) {
|
||||
consume(select(f, wrapper<Child>()))
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !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>() }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: Sam.java
|
||||
|
||||
public interface Sam<K> {
|
||||
Sam.Result<K> compute();
|
||||
|
||||
public static class Result<V> {
|
||||
public static <V> Sam.Result<V> create(V value) {}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Foo.java
|
||||
|
||||
public class Foo {
|
||||
public static <T> void foo(Sam<T> var1) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(e: ErrorType) {
|
||||
Foo.foo {
|
||||
Sam.Result.<!INAPPLICABLE_CANDIDATE!>create<!>(e)
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <K> foo(t: K?) = Inv<K>()
|
||||
|
||||
fun <T> bar(t: T) = foo(t)
|
||||
fun <V1> bar1(t: V1): Inv<V1> = foo(t)
|
||||
fun <V2> bar2(t: V2): Inv<V2> = foo(t)
|
||||
|
||||
fun <S> select(x: S, y: S): S = x
|
||||
|
||||
fun <T> fail(t: T?) = if (t == null) bar(t) else bar(t)
|
||||
fun <F> fail1(t: F?, n: Nothing?) = select(bar1(n), bar2(t!!))
|
||||
fun <F> fail2(t: F?, n: Nothing?) = if (t == null) bar1(t) else bar2(t)
|
||||
fun <F> fail3(t: F?) = select(bar1(null), bar2(t?.let { it }))
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class Foo<T>
|
||||
|
||||
fun <T> foo1(f: (T) -> Unit): Foo<T> = Foo()
|
||||
inline fun <reified T> foo2(f: (T) -> Unit): Foo<T> = Foo()
|
||||
|
||||
fun test1() {
|
||||
val f1: Foo<out Int> = foo1 { it checkType { _<Int>() } }
|
||||
val f2: Foo<in Nothing> = foo1 { it checkType { _<Nothing>() } }
|
||||
|
||||
val f3: Foo<out Int> = foo2 { it checkType { _<Int>() } }
|
||||
val f4: Foo<in Nothing> = foo2 { it checkType { _<Nothing>() } }
|
||||
}
|
||||
compiler/testData/diagnostics/tests/inference/constraints/inferTypeFromCapturedStarProjection.fir.kt
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
interface Box<out R>
|
||||
fun <R> List<Box<R>>.choose(): Box<R>? = TODO()
|
||||
fun list(): List<Box<*>> = TODO()
|
||||
|
||||
fun f() = list().choose()
|
||||
@@ -0,0 +1,21 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// AssertionError in ConstraintSystem(The constraint shouldn't contain different type variables on both sides: Y <: X)
|
||||
|
||||
class A<X, Y : X>
|
||||
|
||||
class B<X, Y : X>(foo: A<X, Y>) {
|
||||
fun test1(a: A<X, Y>) {
|
||||
B(a)
|
||||
val b: B<X, Y> = B(a)
|
||||
// crash here
|
||||
}
|
||||
}
|
||||
|
||||
class C<X, Z, Y : X>
|
||||
|
||||
class D<X, Z, Y : X>(foo: C<X, Z, Y>) {
|
||||
fun test(a: C<Y, Y, Y>) {
|
||||
val d: D<X, Y, Y> = D(a)
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
package kt7351
|
||||
|
||||
interface Node
|
||||
|
||||
interface Source<T> {
|
||||
fun f() : T
|
||||
}
|
||||
fun <T, S : Source<T>> S.woo() : T = this.f()
|
||||
|
||||
fun Node.append(block : Source<Int>.() -> Unit) {
|
||||
}
|
||||
|
||||
fun crashMe(node : Node) {
|
||||
node.append {
|
||||
woo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
public inline fun <S, T: S> Iterable<T>.reduce1(operation: (S, T) -> S): S = throw Exception()
|
||||
|
||||
fun test(ints: List<Int>) {
|
||||
val f: () -> Unit = {
|
||||
ints.reduce1 { a, b -> a + b }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Inv<I>
|
||||
interface Inv2<I>
|
||||
|
||||
fun <T: Inv2<T>> foo(klass: Inv<T>): String? = null
|
||||
|
||||
fun <X> bar(): Inv<X> = null!!
|
||||
|
||||
fun test() {
|
||||
foo(bar())
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_JAVAC
|
||||
|
||||
// FILE: MySettings.java
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class MySettings<
|
||||
SS extends MySettings<SS, PS, L>,
|
||||
PS extends MyComparableSettings,
|
||||
L extends MySettingsListener<PS>
|
||||
>
|
||||
{
|
||||
public Collection<PS> getLinkedProjectsSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MySettings getSettings() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MyComparableSettings implements Comparable<MyComparableSettings> {}
|
||||
abstract class MySettingsListener<S extends MyComparableSettings> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val a = MySettings.getSettings()
|
||||
a.getLinkedProjectsSettings()
|
||||
a.linkedProjectsSettings
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_JAVAC
|
||||
|
||||
// FILE: MySettings.java
|
||||
|
||||
import java.util.Collection
|
||||
|
||||
class MySettings<
|
||||
SS extends MySettings<SS, PS, L>,
|
||||
PS extends MyComparableSettings,
|
||||
L extends MySettingsListener<PS>
|
||||
>
|
||||
{
|
||||
public Collection<PS> getLinkedProjectsSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MySettings<?, ?, ?> getSettings() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MyComparableSettings implements Comparable<MyComparableSettings> {}
|
||||
abstract class MySettingsListener<S extends MyComparableSettings> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val a = MySettings.getSettings()
|
||||
a.getLinkedProjectsSettings()
|
||||
a.linkedProjectsSettings
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
interface A<T>
|
||||
|
||||
interface In<in T>
|
||||
|
||||
interface Out<out T>
|
||||
|
||||
fun <T: Any> doT(t: T?): T = throw Exception("$t")
|
||||
fun <T: Any> doOut(o: Out<T?>): T { throw Exception("$o") }
|
||||
fun <T: Any> doIn(i: In<T?>) { throw Exception("$i") }
|
||||
fun <T: Any> doA(i: A<T?>) { throw Exception("$i") }
|
||||
|
||||
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>() }
|
||||
|
||||
// T? <: Int => error
|
||||
<!INAPPLICABLE_CANDIDATE!>doIn<!>(i)
|
||||
|
||||
// T? >: Int => error
|
||||
<!INAPPLICABLE_CANDIDATE!>doA<!>(inv)
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun test() {
|
||||
generateException(Data(1), { Data(it.x + 2) })
|
||||
}
|
||||
|
||||
fun <T> generateException(a: T, next: (T) -> T) {}
|
||||
|
||||
class Data<out K>(val x: K)
|
||||
compiler/testData/diagnostics/tests/inference/constraints/recursiveJavaTypeWithStarProjection.fir.kt
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
// FILE: MenuItemBase.java
|
||||
|
||||
public class MenuItemBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {
|
||||
public String getText() { return null; }
|
||||
}
|
||||
|
||||
// FILE: ContextMenuBase.java
|
||||
|
||||
public class ContextMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
|
||||
|
||||
// FILE: SubMenuBase.java
|
||||
|
||||
public class SubMenuBase<C extends ContextMenuBase<C, I, S>, I extends MenuItemBase<C, I, S>, S extends SubMenuBase<C, I, S>> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(m: MenuItemBase<*, *, *>) {
|
||||
m.text
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: Test.java
|
||||
import java.util.Collection;
|
||||
|
||||
public class Test {
|
||||
static <T> Inv<Collection<? extends T>> bar() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
class Inv<E>
|
||||
|
||||
fun <R> foo(x: R, y: Inv<R>) {}
|
||||
|
||||
fun main() {
|
||||
val values: List<Int> = null as List<Int>
|
||||
/*
|
||||
* Before the fix, there was type mismatch during checking `Test.bar()` to pass to `foo`:
|
||||
* Required: Inv<List<Int>>
|
||||
* Found: Inv<(MutableCollection<out Int!>..Collection<Int!>?)>
|
||||
* Constraint `(MutableCollection<out T!>..Collection<T!>?)` from 'Found' (for TypeVariable(R)) has been removed
|
||||
* during fixation TypeVariable(T) due to the constraint for R contained TypeVariable(T).
|
||||
* The problem was that TypeVariable(T) wan't substituted due to `containsConstrainingTypeWithoutProjection` optimization.
|
||||
*/
|
||||
foo(values, Test.bar())
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun testLambda() {
|
||||
val basicTest: (Int) -> Int = myRun {
|
||||
val x: Any? = null
|
||||
if (x is String) return@myRun { it -> x.length <!AMBIGUITY!>+<!> it }
|
||||
if (x !is Int) return@myRun { it -> it }
|
||||
|
||||
{ it -> x + it }
|
||||
}
|
||||
|
||||
val twoLambda: (Int) -> Int = myRun {
|
||||
val x: Int = 1
|
||||
run {
|
||||
val y: Int = 2
|
||||
{ x + y }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline fun <R> myRun(block: () -> R): R = block()
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !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>() }
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !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?>() }
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Foo {
|
||||
var test: String by refreshOnUpdate("str")
|
||||
|
||||
fun <T> refreshOnUpdate(initialValue: T) = RefreshDelegate(initialValue)
|
||||
|
||||
class RefreshDelegate<T>(initialValue: T?) {
|
||||
operator fun getValue(thisRef: Foo, property: KProperty<*>): T = TODO()
|
||||
|
||||
operator fun setValue(thisRef: Foo, property: KProperty<*>, value: T) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
package h
|
||||
//+JDK
|
||||
import java.util.*
|
||||
|
||||
fun <T> id(t: T) : T = t
|
||||
|
||||
fun <T> id1(t: T) = t
|
||||
|
||||
fun <R> elem(t: List<R>): R = t.get(0)
|
||||
|
||||
fun <R> elemAndList(r: R, t: List<R>): R = t.get(0)
|
||||
|
||||
fun <T> both(t1: T, t2: T) : T = t1
|
||||
|
||||
fun test1() {
|
||||
val a = elem(list(2))
|
||||
val b = id(elem(list(2)))
|
||||
val c = id(id1(id(id1(list(33)))))
|
||||
checkSubtype<Int>(a)
|
||||
checkSubtype<Int>(b)
|
||||
checkSubtype<List<Int>>(c)
|
||||
|
||||
val d : ArrayList<Int> = newList()
|
||||
val e : ArrayList<Int> = id(newList())
|
||||
val f : ArrayList<Int> = id(id1(id(id1(newList()))))
|
||||
|
||||
checkSubtype<List<Int>>(d)
|
||||
checkSubtype<List<Int>>(e)
|
||||
checkSubtype<List<Int>>(f)
|
||||
|
||||
val g = elemAndList("", newList())
|
||||
val h = elemAndList<Long>(1, newList<Long>())
|
||||
|
||||
checkSubtype<String>(g)
|
||||
checkSubtype<Long>(h)
|
||||
|
||||
val i = both(1, "")
|
||||
val j = both(id(1), id(""))
|
||||
checkSubtype<Any>(i)
|
||||
checkSubtype<Any>(j)
|
||||
}
|
||||
|
||||
fun <T> list(value: T) : ArrayList<T> {
|
||||
val list = ArrayList<T>()
|
||||
list.add(value)
|
||||
return list
|
||||
}
|
||||
|
||||
fun <S> newList() : ArrayList<S> {
|
||||
return ArrayList<S>()
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package a
|
||||
|
||||
class MyList<T>(t: T) {}
|
||||
|
||||
fun <T> getMyList(t: T) : MyList< T> = MyList(t)
|
||||
fun <T> getMyListToWriteTo(t: T) : MyList< in T> = MyList(t)
|
||||
fun <T> getMyListToReadFrom(t: T) : MyList<out T> = MyList(t)
|
||||
|
||||
fun <T> useMyList (l: MyList< T>, t: T) {}
|
||||
fun <T> writeToMyList (l: MyList< in T>, t: T) {}
|
||||
fun <T> readFromMyList(l: MyList<out T>, t: T) {}
|
||||
|
||||
fun test1(int: Int, any: Any) {
|
||||
val a0 : MyList<Any> = getMyList(int)
|
||||
|
||||
val a1 : MyList<Int> = getMyList(any)
|
||||
|
||||
val a2 : MyList<out Any> = getMyList(int)
|
||||
|
||||
val a3 : MyList<out Any> = getMyListToReadFrom(int)
|
||||
|
||||
val a4 : MyList<in Int> = getMyList(any)
|
||||
|
||||
val a5 : MyList<in Int> = getMyListToWriteTo(any)
|
||||
|
||||
|
||||
val a6 : MyList<in Any> = getMyList<Int>(int)
|
||||
val a7 : MyList<in Any> = getMyList(int)
|
||||
|
||||
val a8 : MyList<in Any> = getMyListToReadFrom<Int>(int)
|
||||
val a9 : MyList<in Any> = getMyListToReadFrom(int)
|
||||
|
||||
val a10 : MyList<out Int> = getMyList<Any>(any)
|
||||
val a11 : MyList<out Int> = getMyList(any)
|
||||
|
||||
val a12 : MyList<out Int> = getMyListToWriteTo<Any>(any)
|
||||
val a13 : MyList<out Int> = getMyListToWriteTo(any)
|
||||
|
||||
useMyList(getMyList(int), int)
|
||||
useMyList(getMyList(any), int)
|
||||
useMyList(getMyList(int), any)
|
||||
|
||||
readFromMyList(getMyList(int), any)
|
||||
readFromMyList(getMyList(any), int)
|
||||
<!INAPPLICABLE_CANDIDATE!>readFromMyList<!><Int>(getMyList(any), int)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>readFromMyList<!><Int>(getMyListToReadFrom(any), int)
|
||||
readFromMyList(getMyListToReadFrom(any), int)
|
||||
|
||||
readFromMyList(getMyListToReadFrom(int), any)
|
||||
|
||||
|
||||
writeToMyList(getMyList(any), int)
|
||||
writeToMyList<Any>(getMyList(int), any)
|
||||
writeToMyList(getMyList<Any>(int), any)
|
||||
writeToMyList(getMyList(int), any)
|
||||
|
||||
writeToMyList(getMyListToWriteTo(any), int)
|
||||
writeToMyList(getMyListToWriteTo(int), any)
|
||||
|
||||
readFromMyList(getMyListToWriteTo(any), any)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>writeToMyList<!>(getMyListToReadFrom(any), any)
|
||||
|
||||
use(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
|
||||
}
|
||||
|
||||
fun use(vararg a: Any) = a
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package b
|
||||
//+JDK
|
||||
|
||||
import java.util.*
|
||||
import java.util.Collections.*
|
||||
|
||||
fun foo(list: List<String>) : String {
|
||||
val w : String = max(list, comparator<String?> {o1, o2 -> 1
|
||||
})
|
||||
return w
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !LANGUAGE: +ExpectedTypeFromCast
|
||||
|
||||
fun foo() = 1
|
||||
|
||||
fun <T> foo() = foo() as T
|
||||
|
||||
fun <T> foo2(): T = TODO()
|
||||
|
||||
val test = foo2().plus("") as String
|
||||
|
||||
fun <T> T.bar() = this
|
||||
val barTest = "".bar() as Number
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !LANGUAGE: +ExpectedTypeFromCast
|
||||
|
||||
fun <T> foo(): T = TODO()
|
||||
|
||||
class A {
|
||||
fun <T> fooA(): T = TODO()
|
||||
}
|
||||
|
||||
fun <V> id(value: V) = value
|
||||
|
||||
val asA = foo().<!UNRESOLVED_REFERENCE!>fooA<!>() as A
|
||||
|
||||
val receiverParenthesized = (foo()).<!UNRESOLVED_REFERENCE!>fooA<!>() as A
|
||||
val no2A = A().fooA().<!UNRESOLVED_REFERENCE!>fooA<!>() as A
|
||||
|
||||
val correct1 = A().fooA() as A
|
||||
val correct2 = foo<A>().fooA() as A
|
||||
val correct3 = A().fooA<A>().fooA() as A
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !LANGUAGE: +ExpectedTypeFromCast
|
||||
|
||||
fun <T> foo(): T = TODO()
|
||||
|
||||
fun <V> id(value: V) = value
|
||||
|
||||
val asString = foo() as String
|
||||
|
||||
val viaId = id(foo()) as String
|
||||
|
||||
val insideId = id(foo() as String)
|
||||
|
||||
val asList = foo() as List<String>
|
||||
|
||||
val asStarList = foo() as List<*>
|
||||
|
||||
val safeAs = foo() as? String
|
||||
|
||||
val fromIs = foo() is String
|
||||
val fromNoIs = foo() !is String
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user