[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
interface A
|
||||
interface B : A
|
||||
|
||||
interface ListA : List<A>
|
||||
interface ListB : List<B>
|
||||
|
||||
interface Z<T> where T : ListA, T : ListB
|
||||
@@ -0,0 +1,54 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
class In<in T>() {
|
||||
fun f(t : T) : Unit {}
|
||||
fun f(t : Int) : Int = 1
|
||||
fun f1(t : T) : Unit {}
|
||||
}
|
||||
|
||||
class Out<out T>() {
|
||||
fun f() : T {throw IllegalStateException()}
|
||||
fun f(a : Int) : Int = a
|
||||
}
|
||||
|
||||
class Inv<T>() {
|
||||
fun f(t : T) : T = t
|
||||
fun inf(t : T) : Unit {}
|
||||
fun outf() : T {throw IllegalStateException()}
|
||||
}
|
||||
|
||||
fun testInOut() {
|
||||
In<String>().f("1");
|
||||
(null as In<in String>).f("1")
|
||||
(null as In<*>).f("1") // Wrong Arg
|
||||
|
||||
In<String>().f(1);
|
||||
(null as In<in String>).f(1)
|
||||
(null as In<*>).f(1);
|
||||
|
||||
Out<Int>().f(1)
|
||||
(null as Out<out Int>).f(1)
|
||||
(null as Out<*>).f(1)
|
||||
|
||||
Out<Int>().f()
|
||||
(null as Out<out Int>).f()
|
||||
(null as Out<*>).f()
|
||||
|
||||
Inv<Int>().f(1)
|
||||
(null as Inv<in Int>).f(1)
|
||||
(null as Inv<out Int>).f(1) // !!
|
||||
(null as Inv<*>).f(1) // !!
|
||||
|
||||
Inv<Int>().inf(1)
|
||||
(null as Inv<in Int>).inf(1)
|
||||
(null as Inv<out Int>).inf(1) // !!
|
||||
(null as Inv<*>).inf(1) // !!
|
||||
|
||||
Inv<Int>().outf()
|
||||
checkSubtype<Int>((null as Inv<in Int>).outf()) // Type mismatch
|
||||
(null as Inv<out Int>).outf()
|
||||
(null as Inv<*>).outf()
|
||||
|
||||
Inv<Int>().<!INAPPLICABLE_CANDIDATE!>outf<!>(1) // Wrong Arg
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// FILE: java/util/Collection.java
|
||||
package java.util;
|
||||
|
||||
public class Collection {
|
||||
public void foo() {}
|
||||
}
|
||||
|
||||
// FILE: test/Usage.java
|
||||
package test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Usage {
|
||||
void foo(Collection c) {
|
||||
c.foo();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
package test
|
||||
|
||||
fun foo(u: Usage) {
|
||||
u.foo(null)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package p
|
||||
|
||||
public fun foo(a: Any) {
|
||||
a is Map<Int>
|
||||
a is Map
|
||||
a is Map<out Any?, Any?>
|
||||
a is Map<*, *>
|
||||
a is Map<<!SYNTAX!><!>>
|
||||
a is List<Map>
|
||||
a is List
|
||||
a is Int
|
||||
|
||||
(a as Map) is Int
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public fun foo(a: Any, b: Map) {
|
||||
when (a) {
|
||||
is Map<Int> -> {}
|
||||
is Map -> {}
|
||||
is Map<out Any?, Any?> -> {}
|
||||
is Map<*, *> -> {}
|
||||
is Map<<!SYNTAX!><!>> -> {}
|
||||
is List<Map> -> {}
|
||||
is List -> {}
|
||||
is Int -> {}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
open class C<T : C<T>>
|
||||
class TestOK : C<TestOK>()
|
||||
class TestFail : C<C<TestFail>>()
|
||||
+1
@@ -0,0 +1 @@
|
||||
class D<A : D<A, String>, B : D<A, B>>
|
||||
@@ -0,0 +1,23 @@
|
||||
// See KT-9438: Enforce the Single Instantiation Inheritance Rule for type parameters
|
||||
|
||||
interface A
|
||||
|
||||
interface B
|
||||
|
||||
interface D<T>
|
||||
|
||||
interface IncorrectF<T : D<A>> where T : D<B>
|
||||
|
||||
interface CorrectF<T> where T : D<A>, T : D<B>
|
||||
|
||||
interface G<T>
|
||||
|
||||
interface IncorrectH<T : G<D<A>>> where T : G<D<T>>
|
||||
|
||||
interface CorrectH<T> where T : G<D<A>>, T : G<D<B>>
|
||||
|
||||
interface incorrectJ<T: G<D<T>>> where T : G<D<T?>>
|
||||
|
||||
interface correctJ<T> where T : G<D<T>>, T : G<D<T?>>
|
||||
|
||||
fun <T> bar() where T : D<A>, T : D<B> {}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface I1
|
||||
interface I2
|
||||
open class C
|
||||
|
||||
interface A1<K, V> where V : K, V : K
|
||||
interface A2<K, V, W> where W : K, W : V
|
||||
interface A3<K, V> where V : I1, V : K, V : I2
|
||||
interface A4<K, V> where K : I1, K : I2, K : C, K : V, V : I2, V : I1
|
||||
|
||||
fun <K, V> f1() where V : K, V : K {}
|
||||
fun <K, V, W> f2() where W : K, W : V {
|
||||
fun <T> f3() where T : K, T : V {}
|
||||
fun <T> f4() where T : K, T : K {}
|
||||
}
|
||||
fun <K, V, W> f3() where W : K, W : V, W : Any {}
|
||||
@@ -0,0 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun <T> foo(t: T<String, Int>) {}
|
||||
|
||||
interface A
|
||||
class B<T: A>
|
||||
fun <T> foo1(t: T<B<String>>) {}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class X {
|
||||
abstract class Y<T : Any>
|
||||
|
||||
fun <T : Any> foo(y: Y<T>, t: T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun testStar(y: X.Y<*>, t: Any) {
|
||||
X().<!INAPPLICABLE_CANDIDATE!>foo<!>(y, t)
|
||||
}
|
||||
|
||||
fun testOut(y: X.Y<out Any>, t: Any) {
|
||||
X().<!INAPPLICABLE_CANDIDATE!>foo<!>(y, t)
|
||||
}
|
||||
|
||||
fun testIn(y: X.Y<in Any>, t: Any) {
|
||||
X().foo(y, t)
|
||||
}
|
||||
|
||||
fun <T : Any> testWithParameter(y: X.Y<T>, t: Any) {
|
||||
X().<!INAPPLICABLE_CANDIDATE!>foo<!>(y, t)
|
||||
}
|
||||
|
||||
fun <T : Any> testWithCapturedParameter(y: X.Y<out T>, t: Any) {
|
||||
X().<!INAPPLICABLE_CANDIDATE!>foo<!>(y, t)
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// NI_EXPECTED_FILE
|
||||
private class Outer<E> {
|
||||
private inner class Inner<out F> {
|
||||
private fun <G> foo() = {
|
||||
fun baz() = {
|
||||
class Local {
|
||||
val e: E = magic()
|
||||
val f: F = magic()
|
||||
val g: G = magic()
|
||||
}
|
||||
Local()
|
||||
}
|
||||
baz()()
|
||||
}
|
||||
|
||||
private var doubleCharSequenceInt = Outer<Double>().Inner<CharSequence>().foo<Int>()()
|
||||
private var doubleStringNumber = Outer<Double>().Inner<String>().foo<Number>()()
|
||||
private var doubleStringInt = Outer<Double>().Inner<String>().foo<Int>()()
|
||||
|
||||
private fun bar() {
|
||||
doubleCharSequenceInt = doubleStringNumber
|
||||
doubleCharSequenceInt = doubleStringInt
|
||||
|
||||
doubleStringInt = Outer<Double>().Inner<String>().foo<Int>()()
|
||||
|
||||
doubleStringInt.e.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Double>() }
|
||||
doubleStringInt.f.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
doubleStringInt.g.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> magic(): T = null!!
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T> magic(): T = null!!
|
||||
|
||||
class Q {
|
||||
private fun <E> foo() = {
|
||||
class C {
|
||||
val prop: E = magic()
|
||||
}
|
||||
C()
|
||||
}
|
||||
|
||||
private var x = foo<CharSequence>()()
|
||||
private var y = foo<String>()()
|
||||
|
||||
fun bar() {
|
||||
x = y
|
||||
x = foo<CharSequence>()()
|
||||
y = foo<String>()()
|
||||
|
||||
x.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence>() }
|
||||
y.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
}
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T> magic(): T = null!!
|
||||
|
||||
class Q {
|
||||
private fun <E, F> foo() = {
|
||||
class C<G> {
|
||||
val e: E = magic()
|
||||
val f: F = magic()
|
||||
val g: G = magic()
|
||||
}
|
||||
C<F>()
|
||||
}
|
||||
|
||||
private var x = foo<CharSequence, Number>()()
|
||||
|
||||
fun bar() {
|
||||
x.e.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence>() }
|
||||
x.f.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Number>() }
|
||||
x.g.checkType { _<Number>() }
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <T> magic(): T = null!!
|
||||
|
||||
class Q {
|
||||
private fun <E> foo() =
|
||||
object {
|
||||
val prop: E = magic()
|
||||
}
|
||||
|
||||
private var x = foo<CharSequence>()
|
||||
private var y = foo<String>()
|
||||
|
||||
fun bar() {
|
||||
x = y
|
||||
x = foo<CharSequence>()
|
||||
y = foo<String>()
|
||||
|
||||
x.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence>() }
|
||||
y.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
fun <E> foo(x: Any, y: Any) : Any {
|
||||
class C
|
||||
// without E?
|
||||
if(x is C) {
|
||||
return x
|
||||
}
|
||||
|
||||
if (1 == 2) {
|
||||
x as C
|
||||
}
|
||||
|
||||
if (2 == 3) {
|
||||
x as? C
|
||||
}
|
||||
|
||||
class Outer<F> {
|
||||
inner class Inner
|
||||
}
|
||||
|
||||
// bare type
|
||||
if (y is Outer.Inner) {
|
||||
return y
|
||||
}
|
||||
|
||||
y as Outer<*>.Inner
|
||||
|
||||
return C()
|
||||
}
|
||||
|
||||
fun noTypeParameters(x: Any) : Any {
|
||||
class C
|
||||
if(x is C) {
|
||||
return x
|
||||
}
|
||||
|
||||
return C()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
interface In<in E>
|
||||
|
||||
class En<T> : In<T>
|
||||
class A : In<A>
|
||||
fun <T> select(x: T, y: T): T = x ?: y
|
||||
|
||||
// Return type should be In<*> nor In<out Any?>
|
||||
fun foobar(e: En<*>) = select(A(), e)
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
interface In<in E>
|
||||
class A : In<A>
|
||||
class B : In<B>
|
||||
fun <T> select(x: T, y: T) = x ?: y
|
||||
|
||||
// Return type should be In<*> nor In<out Any?>
|
||||
fun foobar(a: A, b: B) = select(a, b)
|
||||
@@ -0,0 +1,7 @@
|
||||
fun <T : F?, F : T?> foo1() {}
|
||||
|
||||
fun <T : F?, F : E, E : F?> foo2() {}
|
||||
|
||||
fun <T, F> foo3() where T : F?, F : T {}
|
||||
|
||||
fun <T, F, E> foo4() where T : F?, F : E, E : F? {}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A1<T : F?, F : T?>
|
||||
|
||||
class A2<T : F?, F : E, E : F?>
|
||||
|
||||
class A3<T, F> where T : F?, F : T?
|
||||
|
||||
class A4<T, F, E> where T : F?, F : E, E : F
|
||||
@@ -0,0 +1,15 @@
|
||||
// !CHECK_TYPE
|
||||
// SKIP_TXT
|
||||
fun test(b: S) {
|
||||
b.collect(toList()) checkType { <!UNRESOLVED_REFERENCE!>_<!><Inv<String>>() }
|
||||
}
|
||||
|
||||
interface S {
|
||||
fun <R> collect(collector: C<in String, R>): R
|
||||
}
|
||||
|
||||
class C<X, Y>
|
||||
|
||||
fun <T> toList(): C<T, Inv<T>> = null!!
|
||||
|
||||
class Inv<Q>
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// SKIP_TXT
|
||||
// Issues: KT-25105
|
||||
|
||||
class Message1
|
||||
class Task<T>
|
||||
object Message2
|
||||
enum class Message3
|
||||
data class Message4(val x: Int)
|
||||
|
||||
sealed class Message5<T> {
|
||||
open fun <A : T> execute() {}
|
||||
}
|
||||
|
||||
interface Manager<T> {
|
||||
fun <A : T> execute1(task: Task<A>) {}
|
||||
fun <T : Int> execute2(task: T) {}
|
||||
fun <T : Message2> execute3() {}
|
||||
fun <A : T> execute4() {}
|
||||
fun <A : T> execute5() {}
|
||||
val <A : T> A.x get() = 10
|
||||
var <A : T> A.y
|
||||
get() = 10
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
object MessageManager1 : Manager<Message1> {
|
||||
override fun <T : Message1> execute1(task: Task<T>) {}
|
||||
override fun <T : Int> execute2(task: T) {}
|
||||
override fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
object MessageManager2 : Manager<Message3> {
|
||||
override fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
object MessageManager3 : Manager<Message4> {
|
||||
override fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
class MessageManager4 : Manager<Message1> {
|
||||
override fun <T : Message1> execute1(task: Task<T>) {}
|
||||
override fun <T : Int> execute2(task: T) {}
|
||||
override fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
class MessageManager5 : Manager<Message3> {
|
||||
override fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
class MessageManager6 : Manager<Message4> {
|
||||
override fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
interface MessageManager7 : Manager<Message4> {
|
||||
override fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
interface MessageManager8 : Manager<Message1> {
|
||||
override fun <T : Message1> execute1(task: Task<T>) {}
|
||||
override fun <T : Int> execute2(task: T) {}
|
||||
override fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
interface MessageManager9 : Manager<Message3> {
|
||||
override fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
object MessageManager10 : Message5<Int>() {
|
||||
override fun <T : Int> execute() {}
|
||||
}
|
||||
|
||||
class MessageManager11<A> : Message5<Message5<A>>() {
|
||||
override fun <T : Message5<A>> execute() {}
|
||||
}
|
||||
|
||||
data class MessageManager12(val x: Int) : Message5<Message2>() {
|
||||
override fun <T : Message2> execute() {}
|
||||
}
|
||||
|
||||
sealed class MessageManager13<A> : Message5<A>() {
|
||||
override fun <T : A> execute() {}
|
||||
}
|
||||
|
||||
class MessageManager14 : Manager<Message2> {
|
||||
override val <T : Message2> T.x get() = 10
|
||||
override var <T : Message2> T.y
|
||||
get() = 10
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
object MessageManager15 : Manager<Int> {
|
||||
override val <T : Int> T.x get() = 10
|
||||
override var <T : Int> T.y
|
||||
get() = 10
|
||||
set(value) {}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// SKIP_TXT
|
||||
// Issues: KT-25105
|
||||
|
||||
class Message1
|
||||
class Task<T>
|
||||
object Message2
|
||||
enum class Message3
|
||||
data class Message4(val x: Int)
|
||||
interface Manager<T> {}
|
||||
|
||||
object MessageManager1 : Manager<Message1> {
|
||||
fun <T : Message1> execute1(task: Task<T>) {}
|
||||
fun <T : Int> execute2(task: T) {}
|
||||
fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
object MessageManager2 : Manager<Message3> {
|
||||
fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
object MessageManager3 : Manager<Message4> {
|
||||
fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
class MessageManager4 : Manager<Message1> {
|
||||
fun <T : Message1> execute1(task: Task<T>) {}
|
||||
fun <T : Int> execute2(task: T) {}
|
||||
fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
class MessageManager5 : Manager<Message3> {
|
||||
fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
class MessageManager6 : Manager<Message4> {
|
||||
fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
interface MessageManager7 : Manager<Message4> {
|
||||
fun <T : Message4> execute5() {}
|
||||
}
|
||||
|
||||
interface MessageManager8 : Manager<Message1> {
|
||||
fun <T : Message1> execute1(task: Task<T>) {}
|
||||
fun <T : Int> execute2(task: T) {}
|
||||
fun <T : Message2> execute3() {}
|
||||
}
|
||||
|
||||
interface MessageManager9 : Manager<Message3> {
|
||||
fun <T : Message3> execute4() {}
|
||||
}
|
||||
|
||||
object MessageManager10 : Message5<Int>() {
|
||||
fun <T : Int> execute() {}
|
||||
}
|
||||
|
||||
class MessageManager11<A> : Message5<Message5<A>>() {
|
||||
fun <T : Message5<A>> execute() {}
|
||||
}
|
||||
|
||||
data class MessageManager12(val x: Int) : Message5<Message2>() {
|
||||
fun <T : Message2> execute() {}
|
||||
}
|
||||
|
||||
sealed class MessageManager13<A> : Message5<A>() {
|
||||
fun <T : A> execute() {}
|
||||
}
|
||||
|
||||
class MessageManager14 : Manager<Message2> {
|
||||
val <T : Message2> T.x get() = 10
|
||||
var <T : Message2> T.y
|
||||
get() = 10
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
object MessageManager15 : Manager<Int> {
|
||||
val <T : Int> T.x get() = 10
|
||||
var <T : Int> T.y
|
||||
get() = 10
|
||||
set(value) {}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
|
||||
class Foo<T> {
|
||||
class Bar<X> {
|
||||
class Baz {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> a() {}
|
||||
|
||||
fun test() {
|
||||
Foo::class
|
||||
Foo.Bar::class
|
||||
Foo.Bar.Baz::class
|
||||
|
||||
a<Foo.Bar<String>>()
|
||||
a<Foo.Bar.Baz>()
|
||||
|
||||
Foo<String>.Bar::class
|
||||
Foo<String>.Bar.Baz::class
|
||||
|
||||
a<Foo<String>.Bar>()
|
||||
a<Foo<String>.Bar.Baz>()
|
||||
|
||||
a<Foo.Bar<Int>>()
|
||||
a<Foo.Bar<Int>.Baz>()
|
||||
}
|
||||
|
||||
fun <T: Foo<String.Bar>> x() {}
|
||||
fun Foo<String>.Bar.ext() {}
|
||||
|
||||
fun ex1(a: Foo<String>.Bar<String>): Foo<String>.Bar<String> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class Outer<E> {
|
||||
inner class Inner<F, G> {
|
||||
inner abstract class Inner2Base
|
||||
inner class Inner2 : Inner2Base()
|
||||
|
||||
inner abstract class Inner3Base<B>
|
||||
inner class Inner3<H> : Inner3Base<H>()
|
||||
}
|
||||
|
||||
fun foo(x: Outer<*>.Inner<*, *>.Inner2Base) {
|
||||
if (x is Inner.Inner2) return
|
||||
}
|
||||
}
|
||||
|
||||
fun bare(x: Outer<*>.Inner<*, *>.Inner2Base, y: Outer<*>.Inner<*, *>.Inner3Base<Int>) {
|
||||
if (x is Outer.Inner.Inner2) return
|
||||
if (y is Outer.Inner.Inner3) return
|
||||
if (y is Outer<String>.Inner.Inner3) return
|
||||
if (y is Outer.Inner<String, Int>.Inner3<Double>) return
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
open class SuperOuter<E> {
|
||||
inner open class SuperInner<F>
|
||||
}
|
||||
|
||||
class DerivedOuter<G> : SuperOuter<G>() {
|
||||
inner class DerivedInner<H> : SuperOuter<G>.SuperInner<H>()
|
||||
}
|
||||
|
||||
fun bare(x: SuperOuter<*>.SuperInner<*>, y: Any?) {
|
||||
if (x is SuperOuter.SuperInner) return
|
||||
if (y is SuperOuter.SuperInner) {
|
||||
return
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class Outer<E : Any> {
|
||||
inner class Inner<F, G>
|
||||
}
|
||||
|
||||
val x: Outer<String?>.Inner<String, Int> = null!!
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
open class Outer<E> {
|
||||
inner class Inner<F>
|
||||
|
||||
}
|
||||
|
||||
class Derived : Outer<String>() {
|
||||
// Inner<Int> here means Outer<String>.Inner<Int>
|
||||
fun foo(x: Inner<Int>) {}
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object : Outer<String>()
|
||||
|
||||
// Does not work, could be Outer<String>.Inner<Int>
|
||||
// TODO: Should work?
|
||||
fun foo(x: Inner<Int>) {
|
||||
// Inner<Char>() call use companion as implicit receiver
|
||||
val y: Outer<String>.Inner<Char> = Inner<Char>()
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: -ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
open class Outer<E> {
|
||||
inner class Inner<F>
|
||||
|
||||
}
|
||||
|
||||
class Derived : Outer<String>() {
|
||||
// Inner<Int> here means Outer<String>.Inner<Int>
|
||||
fun foo(x: Inner<Int>) {}
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object : Outer<String>()
|
||||
|
||||
// Does not work, could be Outer<String>.Inner<Int>
|
||||
// TODO: Should work?
|
||||
fun foo(x: Inner<Int>) {
|
||||
// Inner<Char>() call use companion as implicit receiver
|
||||
val y: Outer<String>.Inner<Char> = Inner<Char>()
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class A<T> {
|
||||
fun foo() {
|
||||
val q = object {
|
||||
open inner class B
|
||||
inner class C : B()
|
||||
|
||||
// No WRONG_NUMBER_OF_TYPE_ARGUMENTS should be reported on these types
|
||||
val x: B = B()
|
||||
val y: C = C()
|
||||
}
|
||||
|
||||
q.x
|
||||
q.y
|
||||
}
|
||||
}
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
|
||||
// !CHECK_TYPE
|
||||
open class Outer<X, Y> {
|
||||
inner class Inner<Z>
|
||||
typealias Alias<W> = Map<W, X>
|
||||
}
|
||||
|
||||
class Derived : Outer<String, Int>() {
|
||||
fun foo(): Inner<Char> = null!!
|
||||
fun baz(): Alias<Char> = null!!
|
||||
}
|
||||
|
||||
|
||||
class A : Outer<Double, Short>() {
|
||||
class B : Outer<Float, Long>() {
|
||||
fun bar(): Inner<String> = null!!
|
||||
fun x(): Alias<String> = null!!
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
Derived().foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><Outer<String, Int>.Inner<Char>>() }
|
||||
Derived().baz() checkType { <!UNRESOLVED_REFERENCE!>_<!><Map<Char, String>>() }
|
||||
A.B().bar() checkType { <!UNRESOLVED_REFERENCE!>_<!><Outer<Float, Long>.Inner<String>>() }
|
||||
A.B().x() checkType { <!UNRESOLVED_REFERENCE!>_<!><Map<String, Float>>() }
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY
|
||||
|
||||
class A<R1, R2, R3, R4>
|
||||
|
||||
private fun <E> foobar() = {
|
||||
open class LocalOuter<X, Y> {
|
||||
inner class LocalInner<Z> {
|
||||
fun a() = A<E, X, Y, Z>()
|
||||
}
|
||||
|
||||
typealias LocalAlias<W> = A<E, X, Y, W>
|
||||
}
|
||||
|
||||
class Derived : LocalOuter<Double, Short>() {
|
||||
fun foo(): LocalInner<Long> = null!!
|
||||
fun bar(): LocalAlias<Char> = null!!
|
||||
}
|
||||
|
||||
Derived()
|
||||
}
|
||||
|
||||
private fun noParameters() = {
|
||||
open class LocalOuter2<X, Y> {
|
||||
inner class LocalInner2<Z> {
|
||||
fun a() = A<Any, X, Y, Z>()
|
||||
}
|
||||
|
||||
typealias LocalAlias2<W> = A<Any, X, Y, W>
|
||||
}
|
||||
|
||||
class Derived2 : LocalOuter2<Double, Short>() {
|
||||
fun foo(): LocalInner2<Long> = null!!
|
||||
fun bar(): LocalAlias2<Char> = null!!
|
||||
}
|
||||
|
||||
Derived2()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var x = foobar<String>()
|
||||
x = foobar<String>()
|
||||
|
||||
x().foo().a() checkType { <!UNRESOLVED_REFERENCE!>_<!><A<String, Double, Short, Long>>() }
|
||||
x().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><A<String, Double, Short, Char>>() }
|
||||
|
||||
x = foobar<Int>()
|
||||
|
||||
var y = noParameters()
|
||||
y = noParameters()
|
||||
|
||||
y().foo().a() checkType { <!UNRESOLVED_REFERENCE!>_<!><A<Any, Double, Short, Long>>() }
|
||||
y().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><A<Any, Double, Short, Char>>() }
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -TOPLEVEL_TYPEALIASES_ONLY
|
||||
|
||||
class A<R1, R2, R3, R4, R5, R6>
|
||||
|
||||
class Outer<T> {
|
||||
inner class Inner<F> {
|
||||
private fun <E> foobar() = {
|
||||
open class LocalOuter<X, Y> {
|
||||
inner class LocalInner<Z> {
|
||||
fun a() = A<T, F, E, X, Y, Z>()
|
||||
}
|
||||
|
||||
typealias LocalAlias<W> = A<T, F, E, X, Y, W>
|
||||
}
|
||||
|
||||
class Derived : LocalOuter<Double, Short>() {
|
||||
fun foo(): LocalInner<Long> = null!!
|
||||
fun bar(): LocalAlias<Char> = null!!
|
||||
}
|
||||
|
||||
Derived()
|
||||
}
|
||||
|
||||
private fun noParameters() = {
|
||||
open class LocalOuter2<X, Y> {
|
||||
inner class LocalInner2<Z> {
|
||||
fun a() = A<T, F, Any, X, Y, Z>()
|
||||
}
|
||||
|
||||
typealias LocalAlias2<W> = A<T, F, Any, X, Y, W>
|
||||
}
|
||||
|
||||
class Derived2 : LocalOuter2<Double, Short>() {
|
||||
fun foo(): LocalInner2<Long> = null!!
|
||||
fun bar(): LocalAlias2<Char> = null!!
|
||||
}
|
||||
Derived2()
|
||||
}
|
||||
|
||||
fun test(z: Outer<String>.Inner<F>) {
|
||||
var x = foobar<String>()
|
||||
x = foobar<String>()
|
||||
|
||||
x().foo().a() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><A<T, F, String, Double, Short, Long>>() }
|
||||
x().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!INAPPLICABLE_CANDIDATE!>_<!><A<T, F, String, Double, Short, Char>>() }
|
||||
|
||||
x = foobar<Int>()
|
||||
x = z.foobar<String>()
|
||||
|
||||
var y = noParameters()
|
||||
y = noParameters()
|
||||
|
||||
y().foo().a() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><A<T, F, Any, Double, Short, Long>>() }
|
||||
y().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!INAPPLICABLE_CANDIDATE!>_<!><A<T, F, Any, Double, Short, Char>>() }
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
|
||||
// !CHECK_TYPE
|
||||
open class Outer<X, Y> {
|
||||
inner class Inner<Z>
|
||||
typealias Alias<W> = Map<W, X>
|
||||
}
|
||||
|
||||
open class BaseDerived1<E, F> : Outer<F, E>()
|
||||
open class BaseDerived2<X> : BaseDerived1<String, X>()
|
||||
|
||||
class Derived : BaseDerived2<Int>() {
|
||||
fun foo(): Inner<Char> = null!!
|
||||
fun baz(): Alias<Char> = null!!
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
Derived().foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><Outer<Int, String>.Inner<Char>>() }
|
||||
Derived().baz() checkType { <!UNRESOLVED_REFERENCE!>_<!><Map<Char, Int>>() }
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
interface Inv<X>
|
||||
class Outer<E> {
|
||||
inner class Inner
|
||||
|
||||
class Nested : Inv<Inner>
|
||||
object Obj : Inv<Inner>
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// !CHECK_TYPE
|
||||
open class Outer<E> {
|
||||
inner open class Inner<F> {
|
||||
inner class Inner2<D> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DerivedOuter : Outer<String>() {
|
||||
inner class DerivedInner : Inner<Int>() {
|
||||
fun foo(): Inner2<Char> = null!!
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
DerivedOuter().DerivedInner().foo() checkType { <!UNRESOLVED_REFERENCE!>_<!><Outer<String>.Inner<Int>.Inner2<Char>>() }
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
import Outer.Inner
|
||||
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner
|
||||
|
||||
fun foo() {
|
||||
class E
|
||||
val x: Inner = Inner()
|
||||
}
|
||||
|
||||
class Nested {
|
||||
fun bar(x: Inner) {}
|
||||
}
|
||||
}
|
||||
|
||||
class E
|
||||
|
||||
fun bar(x: Inner) {}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
open class Super<T> {
|
||||
inner open class Inner {
|
||||
}
|
||||
}
|
||||
|
||||
class Sub : Super<String>() {
|
||||
// TODO: it would be nice to have a possibility to omit explicit type argument in supertype
|
||||
inner class SubInner : Super<String>.Inner() {}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
open class Super<T> {
|
||||
inner open class Inner {
|
||||
}
|
||||
}
|
||||
|
||||
class Sub : Super<String>() {
|
||||
inner class SubInner : Super<String>.Inner {
|
||||
constructor()
|
||||
constructor(x: Int) : super() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner<F> {
|
||||
fun foo() = this
|
||||
fun baz(): Inner<String> = null!!
|
||||
}
|
||||
|
||||
fun innerFactory(): Outer<E>.Inner<String> = null!!
|
||||
|
||||
fun bar() = Inner<E>()
|
||||
fun set(inner: Inner<out E>) {}
|
||||
|
||||
fun inside() {
|
||||
innerFactory().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Inner<String>>() }
|
||||
}
|
||||
}
|
||||
|
||||
fun factoryString(): Outer<String>.Inner<String> = null!!
|
||||
|
||||
fun <T, Y> infer(x: T, y: Y): Outer<T>.Inner<Y> = null!!
|
||||
val inferred = infer("", 1)
|
||||
|
||||
fun main() {
|
||||
val outer = Outer<String>()
|
||||
|
||||
checkSubtype<Outer<String>.Inner<String>>(outer.bar())
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Outer<String>.Inner<Int>>(outer.Inner<Int>())
|
||||
checkSubtype<Outer<*>.Inner<*>>(outer.bar())
|
||||
checkSubtype<Outer<*>.Inner<*>>(outer.Inner<Int>())
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Outer<CharSequence>.Inner<CharSequence>>(outer.bar())
|
||||
checkSubtype<Outer<CharSequence>.Inner<CharSequence>>(outer.Inner())
|
||||
|
||||
outer.set(outer.bar())
|
||||
outer.set(outer.Inner())
|
||||
|
||||
val x: Outer<String>.Inner<String> = factoryString()
|
||||
outer.set(x)
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
|
||||
class Outer<E> {
|
||||
inner open class InnerBase<F>
|
||||
inner class Inner<H> : InnerBase<H>() {
|
||||
val prop: E = null!!
|
||||
}
|
||||
|
||||
fun foo(x: InnerBase<String>, y: Any?, z: Outer<*>.InnerBase<String>) {
|
||||
if (x is Inner) {
|
||||
x.prop.checkType { _<E>() }
|
||||
}
|
||||
|
||||
if (y is Inner) return
|
||||
|
||||
if (z is Inner) {
|
||||
z.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
|
||||
return
|
||||
}
|
||||
|
||||
if (y is Outer<*>.Inner<*>) {
|
||||
y.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(x: InnerBase<String>, y: Any?, z: Outer<*>.InnerBase<String>) {
|
||||
x as Inner
|
||||
y as Inner
|
||||
z as Inner
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class Outer<out E, in F> {
|
||||
inner class Inner {
|
||||
fun unsafe1(x: E) {}
|
||||
fun unsafe2(x: Collection<E?>) {}
|
||||
fun unsafe3(): F? = null
|
||||
fun unsafe4(): Collection<F>? = null
|
||||
}
|
||||
|
||||
// Should be errors
|
||||
// Refinement of variance checker is needed
|
||||
fun foo(x: Inner) {}
|
||||
fun bar(): Inner? = null
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// JAVAC_EXPECTED_FILE
|
||||
import java.util.*
|
||||
|
||||
class A<T> : AbstractCollection<T>() {
|
||||
override fun iterator(): MyIt = MyIt()
|
||||
|
||||
override val size: Int
|
||||
get() = 1
|
||||
|
||||
inner class MyIt : MutableIterator<T> {
|
||||
override fun next(): T {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <E> commonSupertype(x: E, y: E): E = x
|
||||
|
||||
fun foo() {
|
||||
var myIt = A<String>().iterator()
|
||||
myIt = A<Int>().iterator()
|
||||
|
||||
val csIt: Iterator<CharSequence> = A<String>().iterator()
|
||||
|
||||
commonSupertype(A<String>().iterator(), A<Int>().iterator()).checkType { _<A<out Any>.MyIt>() }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
// FILE: Outer.java
|
||||
|
||||
public class Outer<E> {
|
||||
public class Inner<F> {
|
||||
E foo() {}
|
||||
F bar() {}
|
||||
|
||||
Outer<E> outer() {}
|
||||
}
|
||||
|
||||
Inner<E> baz() { }
|
||||
void set(Inner<String> x) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main() {
|
||||
var outerStr: Outer<String> = Outer()
|
||||
outerStr.baz().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Outer<String>.Inner<String>>() }
|
||||
|
||||
val strInt: Outer<String>.Inner<Int> = outerStr.Inner()
|
||||
|
||||
strInt.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
strInt.bar().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
|
||||
strInt.outer().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Outer<String>>() }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// !CHECK_TYPE
|
||||
// FILE: BaseOuter.java
|
||||
// See KT-10285
|
||||
public class BaseOuter<H> {
|
||||
abstract public class BaseInner<E, F> {
|
||||
public H foo1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public E foo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public F foo3() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Outer.java
|
||||
public class Outer<H> extends BaseOuter<H> {
|
||||
public BaseInner<Double, String> bar() { return null; }
|
||||
public class Inner extends BaseOuter<H>.BaseInner<Double, String> {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x1: Outer<Int>, x2: Outer<Int>.Inner) {
|
||||
x1.bar().foo1().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
|
||||
x1.bar().foo2().checkType { _<Double>() }
|
||||
x1.bar().foo3().checkType { _<String>() }
|
||||
|
||||
x2.foo1().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
|
||||
x2.foo2().checkType { _<Double>() }
|
||||
x2.foo3().checkType { _<String>() }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
open class Super<T> {
|
||||
inner open class Inner {
|
||||
open fun getOuter(): Super<T> = throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
class Sub<T1>(): Super<T1>() {
|
||||
inner class SubInner : Super<T1>.Inner() { // 'Inner' is unresolved
|
||||
// Also, T1 is not resolved to anything, and not marked as resolved
|
||||
init {
|
||||
val x: Super<T1>.Inner = this // T1 is not resolved to anything
|
||||
}
|
||||
|
||||
override fun getOuter(): Sub<T1> = throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
interface T<E> {
|
||||
fun f() : E = null!!
|
||||
}
|
||||
open class A<X>() {
|
||||
inner class B() : T<X> {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A<Int>()
|
||||
val b : A<Int>.B = a.B()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class Outer<T> {
|
||||
inner class Inner<R> {
|
||||
fun <S> newInner(): Inner<S> = Inner()
|
||||
//type mismatch
|
||||
fun <U, S> newOuterInner(): Outer<U>.Inner<S> = Outer<U>().Inner<S>()
|
||||
//^ U here is not analyzed
|
||||
fun foo(t: T, r: R) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun test0() {
|
||||
val inner: Outer<Int>.Inner<String> = Outer<Int>().Inner<String>()
|
||||
Outer<Int>().Inner<String>().foo(1, "") // type mismatch on second argument
|
||||
}
|
||||
|
||||
|
||||
fun test1() {
|
||||
Outer<Int>().Inner<String>().newOuterInner<Double, Boolean>().<!UNRESOLVED_REFERENCE!>foo<!>(1.0, true) // type mismatch on 1.0
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import A.B.D
|
||||
import A.B.C
|
||||
import A.B.D.Innermost
|
||||
|
||||
class A<T> {
|
||||
inner class B<F> {
|
||||
inner class C<E>
|
||||
inner class D {
|
||||
inner class Innermost<X>
|
||||
}
|
||||
}
|
||||
|
||||
class Nested {
|
||||
val x: B<String>? = null
|
||||
val y: B<String>.C<String>? = null
|
||||
val z: B<String>.D? = null
|
||||
|
||||
val c: C<Int>? = null
|
||||
val d: D? = null
|
||||
|
||||
val innerMost: Innermost<String>? = null
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner<E> {
|
||||
fun foo(): E = null!!
|
||||
fun outerE() = baz()
|
||||
}
|
||||
|
||||
fun baz(): E = null!!
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val inner = Outer<String>().Inner<Int>()
|
||||
|
||||
inner.foo().checkType { _<Int>() }
|
||||
inner.outerE().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
|
||||
|
||||
class Outer<T> {
|
||||
inner class Inner
|
||||
fun foo(x: Outer<String>.Inner, y: Outer.Inner, z: Inner) {
|
||||
var inner = Inner()
|
||||
x.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Inner>() }
|
||||
x.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Outer<String>.Inner>() }
|
||||
z.checkType { _<Inner>() }
|
||||
z.checkType { _<Outer<T>.Inner>() }
|
||||
|
||||
inner = x
|
||||
}
|
||||
|
||||
class Nested
|
||||
fun bar(x: Outer.Nested) {
|
||||
var nested = Nested()
|
||||
nested = x
|
||||
|
||||
x.checkType { _<Nested>() }
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
// FILE: test.kt
|
||||
|
||||
package test
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner<F, G> {
|
||||
inner class Inner2
|
||||
inner class Inner3<H>
|
||||
}
|
||||
|
||||
class Nested<I> {
|
||||
inner class Inner4<K>
|
||||
}
|
||||
|
||||
object Obj {
|
||||
class Nested2<J> {
|
||||
inner class Inner5<L>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import test.*;
|
||||
|
||||
class A
|
||||
class B
|
||||
class C
|
||||
class D
|
||||
|
||||
fun ok1(): Outer<A>.Inner<B, C>.Inner2 = null!!
|
||||
fun ok2(): Outer<A>.Inner<B, C>.Inner2 = null!!
|
||||
fun ok22(): test.Outer<A>.Inner<B, C>.Inner3<D> = null!!
|
||||
fun ok3(): Outer.Nested<A>.Inner4<B> = null!!
|
||||
fun ok4(): Outer.Obj.Nested2<A>.Inner5<B> = null!!
|
||||
fun ok5(): test.Outer.Obj.Nested2<A>.Inner5<B> = null!!
|
||||
|
||||
// All arguments are resolved
|
||||
fun errorTypeWithArguments(): Q<A>.W<B, C, D>.R.M = null!!
|
||||
|
||||
fun error1(): Outer<A>.Inner<B>.Inner3<C, D> = null!!
|
||||
fun error2(): Outer<A>.Inner<B, C, D>.Inner2 = null!!
|
||||
fun error3(): Outer.Inner<A, B>.Inner3<C> = null!!
|
||||
|
||||
fun error4(): Outer<A>.Nested<B>.Inner4<C> = null!!
|
||||
fun error5(): Outer<A>.Obj.Nested2<B>.Inner5<C> = null!!
|
||||
fun error6(): Outer.Obj<A>.Nested2<B>.Inner5<C> = null!!
|
||||
|
||||
fun error7(): test<String>.Outer.Obj.Nested2<A>.Inner5<B> = null!!
|
||||
@@ -0,0 +1,36 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner {
|
||||
fun foo() = this
|
||||
fun baz(): Inner = this
|
||||
}
|
||||
|
||||
fun bar() = Inner()
|
||||
|
||||
fun set(inner: Inner) {}
|
||||
}
|
||||
|
||||
fun factoryString(): Outer<String>.Inner = null!!
|
||||
|
||||
fun <T> infer(x: T): Outer<T>.Inner = null!!
|
||||
val inferred = infer("")
|
||||
|
||||
fun main() {
|
||||
val outer = Outer<String>()
|
||||
|
||||
checkSubtype<Outer<String>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<String>.Inner>(outer.Inner())
|
||||
checkSubtype<Outer<*>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<*>.Inner>(outer.Inner())
|
||||
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.Inner())
|
||||
|
||||
outer.set(outer.bar())
|
||||
outer.set(outer.Inner())
|
||||
|
||||
val x: Outer<String>.Inner = factoryString()
|
||||
outer.set(x)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<in E> {
|
||||
inner class Inner {
|
||||
fun foo() = this
|
||||
fun baz(): Inner = this
|
||||
}
|
||||
|
||||
fun bar() = Inner()
|
||||
|
||||
fun set(inner: Inner) {}
|
||||
}
|
||||
|
||||
fun factoryString(): Outer<String>.Inner = null!!
|
||||
|
||||
fun <T> infer(x: T): Outer<T>.Inner = null!!
|
||||
val inferred = infer("")
|
||||
|
||||
fun main() {
|
||||
val outer = Outer<CharSequence>()
|
||||
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.Inner())
|
||||
checkSubtype<Outer<*>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<*>.Inner>(outer.Inner())
|
||||
|
||||
checkSubtype<Outer<String>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<String>.Inner>(outer.Inner())
|
||||
|
||||
outer.set(outer.bar())
|
||||
outer.set(outer.Inner())
|
||||
|
||||
val x: Outer<String>.Inner = factoryString()
|
||||
outer.set(x)
|
||||
val y: Outer<CharSequence>.Inner = infer<CharSequence>("")
|
||||
outer.set(y)
|
||||
|
||||
outer.set(infer<Any>(""))
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<out E> {
|
||||
inner class Inner {
|
||||
fun foo() = this
|
||||
fun baz(): Inner = this
|
||||
}
|
||||
|
||||
fun bar() = Inner()
|
||||
|
||||
// Should be unsafe variance error here
|
||||
fun set(inner: Inner) {}
|
||||
}
|
||||
|
||||
fun factoryString(): Outer<String>.Inner = null!!
|
||||
|
||||
fun <T> infer(x: T): Outer<T>.Inner = null!!
|
||||
val inferred = infer("")
|
||||
|
||||
fun main() {
|
||||
val outer = Outer<String>()
|
||||
|
||||
checkSubtype<Outer<String>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<String>.Inner>(outer.Inner())
|
||||
checkSubtype<Outer<*>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<*>.Inner>(outer.Inner())
|
||||
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<CharSequence>.Inner>(outer.Inner())
|
||||
|
||||
outer.set(outer.bar())
|
||||
outer.set(outer.Inner())
|
||||
|
||||
val x: Outer<String>.Inner = factoryString()
|
||||
outer.set(x)
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner {
|
||||
fun foo() = this
|
||||
fun baz(): Inner = this
|
||||
}
|
||||
|
||||
fun bar() = Inner()
|
||||
|
||||
fun set(inner: Inner) {}
|
||||
}
|
||||
|
||||
fun factoryString(): Outer<String>.Inner = null!!
|
||||
|
||||
fun <T> infer(x: T): Outer<T>.Inner = null!!
|
||||
val inferred = infer("")
|
||||
|
||||
fun main() {
|
||||
val outer: Outer<out String> = Outer<String>()
|
||||
|
||||
checkSubtype<Outer<out String>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<out String>.Inner>(outer.Inner())
|
||||
checkSubtype<Outer<*>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<*>.Inner>(outer.Inner())
|
||||
|
||||
checkSubtype<Outer<out CharSequence>.Inner>(outer.bar())
|
||||
checkSubtype<Outer<out CharSequence>.Inner>(outer.Inner())
|
||||
|
||||
outer.set(outer.bar())
|
||||
outer.set(outer.Inner())
|
||||
|
||||
val x: Outer<String>.Inner = factoryString()
|
||||
outer.set(x)
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class Outer<E> {
|
||||
inner class Inner<F> {
|
||||
fun instance() = this@Outer
|
||||
fun foo(): E = null!!
|
||||
fun bar(e: E, f: F) {}
|
||||
fun baz(): F = null!!
|
||||
|
||||
fun act() {
|
||||
foo().checkType { _<E>() }
|
||||
outerE().checkType { _<E>() }
|
||||
instance().checkType { _<Outer<E>>() }
|
||||
instance().outerE().checkType { _<E>() }
|
||||
|
||||
bar(foo(), baz())
|
||||
bar(outerE(), baz())
|
||||
bar(instance().outerE(), baz())
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(topLevel().Inner<E>().baz(), topLevel().Inner<E>().baz())
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(topLevel().Inner<E>().foo(), topLevel().Inner<E>().baz())
|
||||
|
||||
setE(foo())
|
||||
}
|
||||
}
|
||||
|
||||
fun outerE(): E = null!!
|
||||
|
||||
fun setE(e: E) {}
|
||||
fun setInner(inner: Inner<Int>) {}
|
||||
}
|
||||
|
||||
fun topLevel(): Outer<String> = null!!
|
||||
|
||||
fun foo() {
|
||||
val strInt: Outer<String>.Inner<Int> = Outer<String>().Inner()
|
||||
|
||||
strInt.foo().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
strInt.baz().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
|
||||
|
||||
strInt.instance().<!INAPPLICABLE_CANDIDATE!>setE<!>("")
|
||||
strInt.instance().outerE().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
|
||||
strInt.instance().Inner<Double>().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Outer<String>.Inner<Double>>() }
|
||||
|
||||
Outer<String>().<!INAPPLICABLE_CANDIDATE!>setInner<!>(strInt)
|
||||
Outer<CharSequence>().<!INAPPLICABLE_CANDIDATE!>setInner<!>(strInt)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class A
|
||||
interface I0<T : A<Int>>
|
||||
interface I1<T> where T : A<Int>
|
||||
interface I2<T : A<Int>> where T : A<Int>
|
||||
|
||||
fun <E : A<Int>> foo0() {}
|
||||
fun <E> foo1() where E : A<Int> {}
|
||||
fun <E : A<Int>> foo2() where E : A<Int> {}
|
||||
|
||||
val <E : A<Int>> E.p1: Int
|
||||
get() = 1
|
||||
val <E> E.p2: Int where E : A<Int>
|
||||
get() = 1
|
||||
val <E : A<Int>> E.p3: Int where E : A<Int>
|
||||
get() = 1
|
||||
|
||||
// See KT-8200
|
||||
interface X
|
||||
public class EnumAttribute<T : X<T>>(val klass: Class<T>) where T : Enum<T>
|
||||
@@ -0,0 +1 @@
|
||||
class C<T : C<T>>
|
||||
@@ -0,0 +1,2 @@
|
||||
class C<T>
|
||||
fun <T : C<T>> foo() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
interface A
|
||||
fun <T: A, R: T> emptyStrangeMap(): Map<T, R> = TODO()
|
||||
fun test7() : Map<A, A> = emptyStrangeMap()
|
||||
|
||||
fun test() = emptyStrangeMap()
|
||||
@@ -0,0 +1,24 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// KT-5508 Stackoverflow in type substitution
|
||||
|
||||
abstract class A<T> {
|
||||
public abstract fun foo(x: T)
|
||||
public abstract fun bar(x: T)
|
||||
|
||||
public inner abstract class B<S> : A<B<S>>() {
|
||||
public inner class C<U> : B<C<U>>()
|
||||
{
|
||||
// Here B<C<U>> means A<A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>>.B<A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>.C<U>>
|
||||
// while for being a correct override it should be A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>
|
||||
// It happens because at the beginning we search implicit arguments for an outer classes through supertypes
|
||||
// See TypeResolver.computeImplicitOuterClassArguments for clarifications
|
||||
override fun foo(x: B<C<U>>) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun bar(x: A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.IntStream
|
||||
|
||||
fun main() {
|
||||
val xs = IntStream.range(0, 10).mapToObj { it.toString() }
|
||||
.<!INAPPLICABLE_CANDIDATE!>collect<!>(Collectors.toList())
|
||||
<!UNRESOLVED_REFERENCE!>xs[0]<!>
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public interface Collector<T, R>
|
||||
|
||||
class A<out T> {
|
||||
fun foo(): T = null!!
|
||||
}
|
||||
|
||||
public fun <T> toList(): Collector<T, A<T>> = null!!
|
||||
|
||||
interface Stream<T> {
|
||||
public fun <R> collect(collector: Collector<in T, R>): R
|
||||
}
|
||||
fun stream(): Stream<String> = null!!
|
||||
|
||||
fun main() {
|
||||
val stream: Stream<String> = stream()
|
||||
val xs = stream.collect(toList())
|
||||
xs.foo()
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// !CHECK_TYPE
|
||||
// Incorrect "type mismatch" error for generic extension safe call (required not-null, found nullable)
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
public class B<T> {
|
||||
public String gav() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static <T> B<T> create() {
|
||||
return new B();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: A.kt
|
||||
|
||||
class A<T> {
|
||||
fun gav() = ""
|
||||
}
|
||||
fun <R> foo(x: R) = x
|
||||
fun <T> A<T>.bar() = ""
|
||||
fun <T> B<T>.bar() = ""
|
||||
|
||||
fun foo(l: A<String>?) {
|
||||
// No errors should be here
|
||||
foo(l?.bar()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
|
||||
foo(l?.gav()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
|
||||
if (l != null) {
|
||||
foo(l?.bar()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
foo(l?.gav()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
}
|
||||
|
||||
fun fooNotNull(l: A<String>) {
|
||||
// No errors should be here
|
||||
foo(l?.bar()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
foo(l?.gav()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
val l = B.create<String>()
|
||||
foo(l?.bar()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
|
||||
foo(l?.gav()) checkType { <!UNRESOLVED_REFERENCE!>_<!><String?>() }
|
||||
}
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface A {
|
||||
fun foo(): CharSequence
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun foo(): String?
|
||||
}
|
||||
|
||||
fun <T> test(x: T) where T : B, T : A {
|
||||
x.<!AMBIGUITY!>foo<!>()
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !CHECK_TYPE
|
||||
// FILE: A.java
|
||||
public interface A {
|
||||
String foo();
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface B {
|
||||
fun foo(): String?
|
||||
}
|
||||
|
||||
interface C {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
fun <T> test(x: T) where T : B, T : A, T : C {
|
||||
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface A {
|
||||
fun foo(): CharSequence?
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
fun <T> test(x: T) where T : B, T : A {
|
||||
x.<!AMBIGUITY!>foo<!>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface A {
|
||||
val foo: Any?
|
||||
}
|
||||
|
||||
interface C: A {
|
||||
override val foo: String?
|
||||
}
|
||||
interface B: A {
|
||||
override var foo: String
|
||||
}
|
||||
|
||||
fun <T> test(a: T) where T : B, T : C {
|
||||
a.<!AMBIGUITY!>foo<!> = ""
|
||||
a.<!AMBIGUITY!>foo<!> = null
|
||||
|
||||
a.<!AMBIGUITY!>foo<!>.<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface A {
|
||||
val foo: Any?
|
||||
}
|
||||
|
||||
interface C: A {
|
||||
override val foo: String
|
||||
}
|
||||
interface B: A {
|
||||
override var foo: String?
|
||||
}
|
||||
|
||||
fun <T> test(a: T) where T : B, T : C {
|
||||
a.<!AMBIGUITY!>foo<!> = ""
|
||||
a.<!AMBIGUITY!>foo<!> = null
|
||||
|
||||
a.<!AMBIGUITY!>foo<!>.<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><String>() }
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
interface A {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
interface C: A
|
||||
interface B: A
|
||||
|
||||
fun <T> test(x: T) where T : C?, T : B? {
|
||||
x?.foo()
|
||||
if (x != null) {
|
||||
x.foo()
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
interface A {
|
||||
fun <T, E> foo(): E
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun <Q, W> foo(): W
|
||||
}
|
||||
|
||||
fun <T> test(x: T) where T : B, T : A {
|
||||
x.<!AMBIGUITY!>foo<!><String, Int>().<!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// FILE: First.java
|
||||
|
||||
public class First<T extends Sample> {
|
||||
public static <D extends Sample> void bind(First<D> first) {}
|
||||
}
|
||||
|
||||
// FILE: SubFirst.java
|
||||
|
||||
public class SubFirst<D extends Sample> extends First<D> {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface Sample
|
||||
|
||||
fun test(s: SubFirst<*>) {
|
||||
First.bind(s)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
inline fun <T, reified S> foo(x: T?, y: T): T {
|
||||
if (x is S) return x
|
||||
return y
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
// FILE: JClass.java
|
||||
|
||||
public class JClass {
|
||||
public <K> void foo(Key<K> key, K value) {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class Key<T>
|
||||
|
||||
fun <S> select(x: S, y: S): S = x
|
||||
|
||||
fun <T> setValue(key: Key<T>, value: T, j: JClass) {
|
||||
j.foo(key, select(value, null))
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface A<T : CharSequence>
|
||||
|
||||
fun <S : CharSequence?> foo1(a: A<S>) {}
|
||||
|
||||
class B1<E : String?> : A<E>
|
||||
class B2<E : CharSequence?> : A<E>
|
||||
class B3<E> : A<E>
|
||||
|
||||
class B4<E : CharSequence> : A<E>
|
||||
|
||||
fun <X : CharSequence, Y1 : X, Y2: Y1?> foo(a: A<X>, b: A<Y1>, c: A<Y2>) {}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A<T : CharSequence>(x: T)
|
||||
|
||||
fun <E : CharSequence> foo1(x: E) {}
|
||||
fun <E : CharSequence> E.foo2() {}
|
||||
|
||||
fun <F : String?> bar(x: F) {
|
||||
<!INAPPLICABLE_CANDIDATE!>A<!>(x)
|
||||
<!INAPPLICABLE_CANDIDATE!>A<!><F>(x)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(x)
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!><F>(x)
|
||||
|
||||
x.<!INAPPLICABLE_CANDIDATE!>foo2<!>()
|
||||
x.<!INAPPLICABLE_CANDIDATE!>foo2<!><F>()
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun <E : String?, T : ((CharSequence) -> Unit)?> foo(x: E, y: T) {
|
||||
if (x != null) {
|
||||
y(x)
|
||||
}
|
||||
|
||||
if (y != null) {
|
||||
y(x)
|
||||
}
|
||||
|
||||
if (x != null && y != null) {
|
||||
y(x)
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
fun simpleTypeAndNumberType(b: Comparable<*>?) {
|
||||
if (b is Byte?) {
|
||||
b!!.dec()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> typeParmeterAndNumberType(b: T?) {
|
||||
if (b is Byte?) {
|
||||
b!!.dec()
|
||||
}
|
||||
}
|
||||
|
||||
fun anyAndNumberType(b: Any?) {
|
||||
if (b is Byte?) {
|
||||
b!!.dec()
|
||||
}
|
||||
}
|
||||
|
||||
fun comparableAndNumberType(b: Comparable<Byte>?) {
|
||||
if (b is Byte?) {
|
||||
b!!.dec()
|
||||
}
|
||||
}
|
||||
|
||||
object SeparateTypes {
|
||||
interface A
|
||||
interface B {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun separate(a: A?) {
|
||||
if (a is B?) {
|
||||
a!!.foo()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
abstract class Expr<T>
|
||||
|
||||
class Sum<K>(val e: Expr<K>) : Expr<K?>()
|
||||
|
||||
private fun <V> times(e: Expr<V>, element: V): Expr<V> = TODO()
|
||||
|
||||
private fun <S> foo(e: Expr<S>) {}
|
||||
|
||||
fun test(intExpression: Expr<Int>) {
|
||||
foo(Sum(times(intExpression, 42)))
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface A
|
||||
interface B {
|
||||
fun test() {}
|
||||
}
|
||||
|
||||
fun <K> select(a: K, b: K): K = a
|
||||
|
||||
fun test(a: A?, b: B?) {
|
||||
b as A?
|
||||
a as B?
|
||||
val c = select(a, b)
|
||||
if (c != null) {
|
||||
c.test()
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE
|
||||
|
||||
fun <E> bar(x: E) {}
|
||||
|
||||
fun <T> foo(): T {
|
||||
val x1: T = null
|
||||
val x2: T? = null
|
||||
|
||||
bar<T>(null)
|
||||
bar<T?>(null)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun <T> baz(): T? = null
|
||||
|
||||
fun <T> foobar(): T = null
|
||||
|
||||
class A<F> {
|
||||
fun xyz(x: F) {}
|
||||
|
||||
fun foo(): F {
|
||||
val x1: F = null
|
||||
val x2: F? = null
|
||||
|
||||
xyz(null)
|
||||
bar<F?>(null)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun baz(): F? = null
|
||||
|
||||
fun foobar(): F = null
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fun <T : Any?> foo(x: T) {
|
||||
if (x is String?) {
|
||||
x.length
|
||||
|
||||
if (x != null) {
|
||||
x.length
|
||||
}
|
||||
}
|
||||
|
||||
if (x is String) {
|
||||
x.length
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE
|
||||
|
||||
fun <T : CharSequence?> T.bar1() {}
|
||||
fun CharSequence?.bar2() {}
|
||||
|
||||
fun <T : CharSequence> T.bar3() {}
|
||||
fun CharSequence.bar4() {}
|
||||
|
||||
fun <T : CharSequence?> foo(x: T) {
|
||||
|
||||
if (x != null) {
|
||||
if (x != null) {}
|
||||
|
||||
x.length
|
||||
x?.length
|
||||
|
||||
x.bar1()
|
||||
x.bar2()
|
||||
x.bar3()
|
||||
x.bar4()
|
||||
|
||||
|
||||
x?.bar1()
|
||||
}
|
||||
|
||||
x.length
|
||||
|
||||
if (x is String) {
|
||||
x.<!AMBIGUITY!>length<!>
|
||||
x?.<!AMBIGUITY!>length<!>
|
||||
|
||||
x.bar1()
|
||||
x.bar2()
|
||||
x.bar3()
|
||||
}
|
||||
|
||||
if (x is CharSequence) {
|
||||
x.length
|
||||
x?.length
|
||||
|
||||
x.bar1()
|
||||
x.bar2()
|
||||
x.bar3()
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE
|
||||
|
||||
fun <T : CharSequence?> T.bar1() {}
|
||||
fun CharSequence?.bar2() {}
|
||||
|
||||
fun <T : CharSequence> T.bar3() {}
|
||||
fun CharSequence.bar4() {}
|
||||
|
||||
fun <T : String?> T.foo() {
|
||||
if (this != null) {
|
||||
if (this != null) {}
|
||||
|
||||
length
|
||||
this?.length
|
||||
|
||||
bar1()
|
||||
bar2()
|
||||
bar3()
|
||||
bar4()
|
||||
|
||||
|
||||
this?.bar1()
|
||||
}
|
||||
|
||||
length
|
||||
|
||||
if (this is String) {
|
||||
length
|
||||
this?.length
|
||||
|
||||
bar1()
|
||||
bar2()
|
||||
bar3()
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE,-UNUSED_PARAMETER,-ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE,-UNUSED_VALUE
|
||||
|
||||
fun <T : CharSequence> bar1(x: T) {}
|
||||
fun bar2(x: CharSequence) {}
|
||||
fun bar3(x: String) {}
|
||||
|
||||
fun <T : CharSequence?> foo(x: T) {
|
||||
var y1: CharSequence = ""
|
||||
var y2: String = ""
|
||||
if (x != null) {
|
||||
if (x != null) {}
|
||||
|
||||
y1 = x
|
||||
y2 = x
|
||||
|
||||
bar1(x)
|
||||
bar1<CharSequence>(x)
|
||||
bar2(x)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar3<!>(x)
|
||||
}
|
||||
|
||||
if (x is String) {
|
||||
y1 = x
|
||||
y2 = x
|
||||
|
||||
bar1(x)
|
||||
bar2(x)
|
||||
bar3(x)
|
||||
}
|
||||
|
||||
if (x is CharSequence) {
|
||||
y1 = x
|
||||
y2 = x
|
||||
|
||||
bar1(x)
|
||||
bar2(x)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar3<!>(x)
|
||||
}
|
||||
|
||||
if (1 == 1) {
|
||||
val y = x!!
|
||||
bar1(x)
|
||||
bar1<CharSequence>(x)
|
||||
bar2(x)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar3<!>(x)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>bar1<!>(y)
|
||||
bar2(y)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar3<!>(y)
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE
|
||||
|
||||
class A<F> {
|
||||
fun <E : F> foo1(x: E) = x
|
||||
fun <E : F?> foo2(x: E) = x
|
||||
|
||||
fun <Z : F, W : Z?> bar(x: F, y: F?, z: Z, w: W) {
|
||||
foo1<F>(x)
|
||||
|
||||
val x1 = foo1(x)
|
||||
x1.checkType { _<F>() }
|
||||
|
||||
foo2<F>(x)
|
||||
|
||||
val x2 = foo2(x)
|
||||
x2.checkType { _<F>() }
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!><F?>(y)
|
||||
foo1(y)
|
||||
foo2<F?>(y)
|
||||
|
||||
val x3 = foo2(y)
|
||||
x3.checkType { _<F?>() }
|
||||
|
||||
foo1<F>(y)
|
||||
foo2<F>(y)
|
||||
|
||||
foo1<Z>(z)
|
||||
|
||||
val x4 = foo1(z)
|
||||
x4.checkType { _<Z>() }
|
||||
|
||||
foo2<Z>(z)
|
||||
|
||||
val x5 = foo2(z)
|
||||
x4.checkType { _<Z>() }
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!><W>(w)
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(w)
|
||||
foo2<W>(w)
|
||||
|
||||
val x6 = foo2(w)
|
||||
x6.checkType { _<W>() }
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!><W>(w)
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE
|
||||
|
||||
class A<F> {
|
||||
class Inv<Q>
|
||||
fun <E : Inv<F>> fooInv1(x: E) = x
|
||||
fun <E : Inv<F?>> fooInv2(x: E) = x
|
||||
|
||||
class In<in Q>
|
||||
fun <E : In<F>> fooIn1(x: E) = x
|
||||
fun <E : In<F?>> fooIn2(x: E) = x
|
||||
|
||||
class Out<out Q>
|
||||
fun <E : Out<F>> fooOut1(x: E) = x
|
||||
fun <E : Out<F?>> fooOut2(x: E) = x
|
||||
|
||||
fun <Z : F, W : Z?> bar() {
|
||||
// F
|
||||
fooInv1<Inv<F>>(Inv<F>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!><Inv<F>>(Inv<F>())
|
||||
fooInv1(Inv<F>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!>(Inv<F>())
|
||||
|
||||
fooIn1<In<F?>>(In<F?>())
|
||||
fooIn2<In<F?>>(In<F?>())
|
||||
fooIn1(In<F?>())
|
||||
fooIn2(In<F?>())
|
||||
|
||||
fooOut1<Out<F>>(Out<F>())
|
||||
fooOut2<Out<F>>(Out<F>())
|
||||
fooOut1(Out<F>())
|
||||
fooOut2(Out<F>())
|
||||
|
||||
// Z
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv1<!><Inv<Z>>(Inv<Z>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!><Inv<Z>>(Inv<Z>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv1<!>(Inv<Z>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!>(Inv<Z>())
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn1<!><In<Z?>>(In<Z?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn2<!><In<Z?>>(In<Z?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn1<!>(In<Z?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn2<!>(In<Z?>())
|
||||
|
||||
fooOut1<Out<Z>>(Out<Z>())
|
||||
fooOut2<Out<Z>>(Out<Z>())
|
||||
fooOut1(Out<Z>())
|
||||
fooOut2(Out<Z>())
|
||||
|
||||
// W
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv1<!><Inv<W>>(Inv<W>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!><Inv<W>>(Inv<W>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv1<!>(Inv<W>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooInv2<!>(Inv<W>())
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn1<!><In<W?>>(In<W?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn2<!><In<W?>>(In<W?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn1<!>(In<W?>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooIn2<!>(In<W?>())
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>fooOut1<!><Out<W>>(Out<W>())
|
||||
fooOut2<Out<W>>(Out<W>())
|
||||
<!INAPPLICABLE_CANDIDATE!>fooOut1<!>(Out<W>())
|
||||
fooOut2(Out<W>())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_VALUE,-UNUSED_VARIABLE,-ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE,-VARIABLE_WITH_REDUNDANT_INITIALIZER
|
||||
|
||||
class A<T : CharSequence?, E1 : T, E2: T?> {
|
||||
fun T.bar() {}
|
||||
|
||||
fun foo(x: E1, y: E2) {
|
||||
x.bar()
|
||||
|
||||
if (1 == 1) {
|
||||
y.<!INAPPLICABLE_CANDIDATE!>bar<!>()
|
||||
}
|
||||
|
||||
x?.bar()
|
||||
y?.bar()
|
||||
|
||||
|
||||
var t: T = x
|
||||
var tN: T? = y
|
||||
|
||||
// condition needed to make smart cast on tN impossible
|
||||
if (1 == 1) {
|
||||
tN = x
|
||||
}
|
||||
|
||||
if (1 == 1) {
|
||||
t = tN
|
||||
}
|
||||
|
||||
t = y
|
||||
|
||||
if (y != null) {
|
||||
t = y
|
||||
}
|
||||
|
||||
if (tN != null) {
|
||||
t = tN
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION,-UNUSED_VARIABLE
|
||||
|
||||
fun <T : CharSequence?> T.bar1() {}
|
||||
fun CharSequence?.bar2() {}
|
||||
|
||||
fun <T : CharSequence> T.bar3() {}
|
||||
|
||||
fun <T : String?> foo(x: T) {
|
||||
x.length
|
||||
x?.length
|
||||
|
||||
if (1 == 1) {
|
||||
x!!.length
|
||||
}
|
||||
|
||||
|
||||
x.bar1()
|
||||
x.bar2()
|
||||
|
||||
x?.bar1()
|
||||
x?.bar2()
|
||||
|
||||
x.<!INAPPLICABLE_CANDIDATE!>bar3<!>()
|
||||
|
||||
x?.let { it.length }
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE
|
||||
|
||||
fun <T : CharSequence?> bar1(x: T) {}
|
||||
|
||||
fun bar2(x: CharSequence?) {}
|
||||
|
||||
fun <T : CharSequence> bar3(x: T) {}
|
||||
|
||||
fun bar4(x: String) {}
|
||||
|
||||
fun <T : String?> foo(x: T) {
|
||||
bar1(x)
|
||||
bar2(x)
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>bar3<!>(x)
|
||||
bar4(x)
|
||||
}
|
||||
@@ -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<*>>>() }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user