[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: A.java
|
||||
public class A {
|
||||
public java.util.List<? extends CharSequence> foo() {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo2(x: A, y: MutableList<out CharSequence>) {
|
||||
x.foo().isEmpty()
|
||||
x.foo().get(0) checkType { <!UNRESOLVED_REFERENCE!>_<!><CharSequence>() }
|
||||
x.foo().iterator() checkType { <!UNRESOLVED_REFERENCE!>_<!><MutableIterator<CharSequence>>() }
|
||||
|
||||
y.isEmpty()
|
||||
y.get(0) checkType { <!UNRESOLVED_REFERENCE!>_<!><CharSequence>() }
|
||||
y.iterator() checkType { <!UNRESOLVED_REFERENCE!>_<!><MutableIterator<CharSequence>>() }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface C<out T>
|
||||
interface MC<T> : C<T> {
|
||||
fun addAll(x: C<T>): Boolean
|
||||
fun addAllMC(x: MC<out T>): Boolean
|
||||
fun addAllInv(x: MC<T>): Boolean
|
||||
}
|
||||
|
||||
interface Open
|
||||
class Derived : Open
|
||||
|
||||
fun <T> mc(): MC<T> = null!!
|
||||
fun <T> c(): C<T> = null!!
|
||||
|
||||
fun foo(x: MC<out Open>) {
|
||||
x.addAll(x)
|
||||
x.addAllMC(x)
|
||||
|
||||
x.addAll(mc<Open>())
|
||||
x.addAllMC(mc<Open>())
|
||||
|
||||
x.addAll(mc<Derived>())
|
||||
x.addAllMC(mc<Derived>())
|
||||
|
||||
x.addAll(c())
|
||||
x.addAll(c<Nothing>())
|
||||
|
||||
x.addAllInv(mc<Open>())
|
||||
x.<!INAPPLICABLE_CANDIDATE!>addAll<!>(1)
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
public abstract class A<E> {
|
||||
fun bar(): String = ""
|
||||
}
|
||||
|
||||
public class B<F> : A<B<F>>()
|
||||
|
||||
fun test(b: B<*>) {
|
||||
// Here `bar` could have dispatch receiver parameter type 'A<B<Captured(*)>>', but it wouldn't work as
|
||||
// since 'b' has type 'A<out B<*>>', so we should approximate dispatch receiver PARAMETER type to make it accept original receiver
|
||||
b.bar()
|
||||
b.bar() checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class A<T> {
|
||||
fun T.foo() {}
|
||||
fun Out<T>.bar() {}
|
||||
}
|
||||
class Out<out E>
|
||||
|
||||
fun test(x: A<out CharSequence>, y: Out<CharSequence>) {
|
||||
with(x) {
|
||||
// TODO: this diagnostic could be replaced with TYPE_MISMATCH_DUE_TO_TYPE_PROJECTION
|
||||
"".foo()
|
||||
y.bar()
|
||||
|
||||
with(y) {
|
||||
bar()
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T> {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
interface B
|
||||
|
||||
public fun <E : B> E.bar() : A<out E> = null!!
|
||||
|
||||
fun baz(x: B) {
|
||||
x.bar().foo()
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: Clazz.java
|
||||
public class Clazz<Psi> {
|
||||
public java.util.Collection<Psi> foo() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Iterable<T>.filterTo(destination: C, predicate: (T) -> Boolean) {}
|
||||
|
||||
fun test(clazz: Clazz<out Any>) {
|
||||
val result = java.util.<!UNRESOLVED_REFERENCE!>ArrayList<!><Any>()
|
||||
clazz.foo().<!INAPPLICABLE_CANDIDATE!>filterTo<!>(result) { x -> true }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
interface A<T>
|
||||
interface B<E> {
|
||||
fun foo(x: A<in E>)
|
||||
}
|
||||
|
||||
fun foo(x: B<in CharSequence>, y: A<CharSequence>) {
|
||||
x.foo(y)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class A<T>
|
||||
fun <T> A<T>.foo(): Collection<T> = null!!
|
||||
|
||||
fun main(a: A<*>, a1: A<out CharSequence>) {
|
||||
// see KT-9571
|
||||
for (i in a.foo()) { }
|
||||
for (i: Any? in a.foo()) { }
|
||||
|
||||
for (i in a1.foo()) { }
|
||||
for (i: CharSequence in a1.foo()) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !CHECK_TYPE
|
||||
import java.util.ArrayList
|
||||
|
||||
class ListOfLists<T>(public val x : ArrayList<ArrayList<T>>)
|
||||
|
||||
fun main() {
|
||||
val a : ArrayList<ArrayList<String>> = ArrayList()
|
||||
val b : ListOfLists<String> = ListOfLists(a)
|
||||
val c : ListOfLists<*> = b
|
||||
val d : ArrayList<ArrayList<*>> = c.x
|
||||
|
||||
c.x checkType { <!UNRESOLVED_REFERENCE!>_<!><ArrayList<out ArrayList<*>>>() }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
interface Subscriber<T>
|
||||
|
||||
interface Observable<T> {
|
||||
fun subscribe(s: Subscriber<in T>)
|
||||
}
|
||||
|
||||
fun foo(o: Observable<out CharSequence>, y: Subscriber<in CharSequence>) = o.subscribe(y) // type safe
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
class A<T> {
|
||||
fun foo(f: (T) -> Unit) {}
|
||||
}
|
||||
|
||||
fun test(a: A<out Number>, b: A<in Number>) {
|
||||
a.foo {
|
||||
it checkType { _<Number>() }
|
||||
}
|
||||
|
||||
b.foo {
|
||||
it checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
|
||||
}
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Out<out T>
|
||||
class In<in T> {
|
||||
fun invoke1(x: T) {}
|
||||
fun invoke2(x: Out<T>) {}
|
||||
}
|
||||
|
||||
interface A<E> {
|
||||
fun foo(): In<E>
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>, y: Out<CharSequence>) {
|
||||
val i = a.foo()
|
||||
// TODO: These diagnostic are wrong, type of 'i' --- 'In<Nothing>' is not projected itself,
|
||||
// but it's approximation result caused by 'a' projection
|
||||
i.invoke1("")
|
||||
i.invoke2(y)
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T> {
|
||||
fun foo(x: T, y: T) {}
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>) {
|
||||
a.foo("", "")
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
// FILE: Clazz.java
|
||||
public class Clazz<T> {
|
||||
public T getT() { return null; }
|
||||
public Clazz<? super T> getSuperClass() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun test(clazz: Clazz<*>) {
|
||||
clazz.t checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
clazz.getSuperClass() checkType { <!UNRESOLVED_REFERENCE!>_<!><Clazz<*>?>() }
|
||||
clazz.getSuperClass().t checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
|
||||
clazz.superClass checkType { <!UNRESOLVED_REFERENCE!>_<!><Clazz<*>?>() }
|
||||
clazz.superClass.t checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
|
||||
// See KT-9294
|
||||
if (clazz.superClass == null) {
|
||||
throw NullPointerException()
|
||||
}
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T> {
|
||||
operator fun plus(x: T): A<T> = this
|
||||
operator fun set(x: Int, y: T) {}
|
||||
operator fun get(x: T) = 1
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>) {
|
||||
a + ""
|
||||
a[1] = ""
|
||||
a[""]
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class Inv<E>
|
||||
class C<R> {
|
||||
fun bindTo(property: Inv<R>) {}
|
||||
}
|
||||
|
||||
fun foo(x: Any?, y: C<*>) {
|
||||
y.<!INAPPLICABLE_CANDIDATE!>bindTo<!>("")
|
||||
|
||||
if (x is C<*>) {
|
||||
x.<!INAPPLICABLE_CANDIDATE!>bindTo<!>("")
|
||||
with(x) {
|
||||
<!INAPPLICABLE_CANDIDATE!>bindTo<!>("")
|
||||
}
|
||||
}
|
||||
|
||||
with(x) {
|
||||
if (this is C<*>) {
|
||||
<!INAPPLICABLE_CANDIDATE!>bindTo<!>("")
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// See KT-7296
|
||||
interface A<T>
|
||||
interface B<T> : A<A<T>>
|
||||
|
||||
fun foo(x : B<*>) {
|
||||
<!INAPPLICABLE_CANDIDATE!>bar1<!>(x) // this should not be valid
|
||||
bar2(x)
|
||||
bar3(x)
|
||||
}
|
||||
|
||||
fun bar1(x : A<A<*>>) { }
|
||||
fun bar2(x : A<out A<*>>) { }
|
||||
fun bar3(x : A<*>) { }
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// See KT-7296
|
||||
interface Out<out F>
|
||||
interface B<T> : Out<Out<T>>
|
||||
|
||||
fun foo(x : B<*>) {
|
||||
bar1(x)
|
||||
bar2(x)
|
||||
}
|
||||
|
||||
fun bar1(x : Out<Out<*>>) { }
|
||||
fun bar2(x : Out<*>) { }
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
// See KT-9893
|
||||
open class A
|
||||
|
||||
public interface I<T : A> {
|
||||
public fun foo(): T?
|
||||
}
|
||||
|
||||
fun acceptA(a: A) {
|
||||
}
|
||||
|
||||
fun main(i: I<*>) {
|
||||
i.foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><A?>() }
|
||||
acceptA(i.foo()) // i.foo() should be nullable but isn't
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
interface A<T : A<T?>?> {
|
||||
fun foo(): T?
|
||||
}
|
||||
fun testA(a: A<*>) {
|
||||
a.foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><A<*>?>() }
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface Clazz<T> {
|
||||
val t: T
|
||||
fun getSuperClass(): Clazz<in T>
|
||||
}
|
||||
|
||||
fun test(clazz: Clazz<*>) {
|
||||
clazz.t checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
clazz.getSuperClass() checkType { <!UNRESOLVED_REFERENCE!>_<!><Clazz<*>>() }
|
||||
clazz.getSuperClass().t checkType { <!UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T> {
|
||||
operator fun plus(x: Out<T>): A<T> = this
|
||||
operator fun set(x: Int, y: Out<T>) {}
|
||||
operator fun get(x: Out<T>) = 1
|
||||
}
|
||||
|
||||
class Out<out F>
|
||||
|
||||
fun test(a: A<out CharSequence>, y: Out<CharSequence>) {
|
||||
a + y
|
||||
a[1] = y
|
||||
a[y]
|
||||
|
||||
a + Out<Nothing>()
|
||||
a[1] = Out<Nothing>()
|
||||
a[Out<Nothing>()]
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class Out<out T> {
|
||||
fun id() = this
|
||||
fun foobar(x: Any) {}
|
||||
}
|
||||
|
||||
class A<E> {
|
||||
inline fun foo(block: () -> E) {}
|
||||
inline fun bar(block: () -> Out<E>) {}
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>, z: Out<CharSequence>) {
|
||||
a.foo {
|
||||
val x: String = 1 // Should be no TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS
|
||||
""
|
||||
}
|
||||
a.bar { Out<CharSequence>() }
|
||||
a.bar { Out() }
|
||||
a.bar { z.id() }
|
||||
|
||||
a.foo {
|
||||
z.foobar(if (1 > 2) return@foo "" else "")
|
||||
""
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Out<out X>
|
||||
class In<in Y>
|
||||
class Inv<Z>
|
||||
|
||||
class A<T> {
|
||||
fun <E : Out<T>> foo1(x: E) = 1
|
||||
fun <F : Inv<T>> foo2(x: F) = 1
|
||||
fun <G : In<T>> foo3(x: G) = 1
|
||||
}
|
||||
|
||||
fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
|
||||
a.foo1(Out<CharSequence>())
|
||||
a.foo1<Out<CharSequence>>(Out())
|
||||
|
||||
a.foo1(Out())
|
||||
a.foo1(Out<Nothing>())
|
||||
|
||||
a.foo2(Inv())
|
||||
a.foo2(Inv<CharSequence>())
|
||||
a.foo2<Inv<CharSequence>>(Inv())
|
||||
|
||||
a.foo3(In())
|
||||
a.foo3(In<CharSequence>())
|
||||
a.foo3<In<CharSequence>>(In())
|
||||
|
||||
b.foo1(Out())
|
||||
b.foo1(Out<CharSequence>())
|
||||
b.foo1<Out<CharSequence>>(Out())
|
||||
|
||||
b.foo2(Inv())
|
||||
b.foo2(Inv<CharSequence>())
|
||||
b.foo2<Inv<CharSequence>>(Inv())
|
||||
|
||||
|
||||
b.foo3(In<CharSequence>())
|
||||
b.foo3<In<CharSequence>>(In())
|
||||
|
||||
b.foo3(In<Any?>())
|
||||
b.foo3(In())
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
interface A<out K> {
|
||||
fun foo(x: @UnsafeVariance K): Unit
|
||||
}
|
||||
|
||||
fun test(a: A<*>) {
|
||||
a.foo(null)
|
||||
a.foo(Any())
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T> {
|
||||
fun foo(vararg x: T) {}
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>, y: Array<out CharSequence>) {
|
||||
a.foo("", "", "")
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>(*y)
|
||||
// TODO: TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS probably redundant
|
||||
a.<!INAPPLICABLE_CANDIDATE!>foo<!>(*y, "")
|
||||
}
|
||||
Reference in New Issue
Block a user