[FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
This commit is contained in:
committed by
Space Team
parent
5cc08fb314
commit
1b27d60307
-12
@@ -1,12 +0,0 @@
|
||||
// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -UNUSED_PARAMETER
|
||||
|
||||
interface Parent
|
||||
object ChildA : Parent
|
||||
object ChildB : Parent
|
||||
|
||||
fun <@kotlin.internal.OnlyInputTypes T> select(a: T, b: T) {}
|
||||
|
||||
fun test() {
|
||||
select(ChildA, ChildB) // should be error
|
||||
select<Any>(ChildA, ChildB) // should be ok
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -UNUSED_PARAMETER
|
||||
|
||||
interface Parent
|
||||
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
open class Base()
|
||||
class CX : Base()
|
||||
class CY : Base()
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
fun <@kotlin.internal.OnlyInputTypes T> foo(a: T, b: T) {}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
fun <@kotlin.internal.OnlyInputTypes T : Any> fooA(a: T, b: T) {}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
fun <@kotlin.internal.OnlyInputTypes T : Base> fooB(a: T, b: T) {}
|
||||
|
||||
|
||||
fun usage(x: CX, y: CY) {
|
||||
foo(x, y) // expected err, got err
|
||||
fooA(x, y) // expected err, got ok
|
||||
fooB(x, y) // expected err, got ok
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
open class Base()
|
||||
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// ISSUE: KT-29307
|
||||
|
||||
fun test_1(map: Map<String, String>) {
|
||||
val x = map[42] // OK
|
||||
}
|
||||
|
||||
open class A
|
||||
|
||||
class B : A()
|
||||
|
||||
fun test_2(map: Map<A, String>) {
|
||||
val x = map[42]
|
||||
}
|
||||
|
||||
fun test_3(m: Map<*, String>) {
|
||||
val x = m[42] // should be ok
|
||||
}
|
||||
|
||||
fun test_4(m: Map<out Number, String>) {
|
||||
val x = m.get(42) // should be ok
|
||||
}
|
||||
|
||||
fun test_5(map: Map<B, Int>, a: A) {
|
||||
map.get(a)
|
||||
}
|
||||
|
||||
fun test_6(map: Map<A, Int>, b: B) {
|
||||
map.get(b)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// ISSUE: KT-29307
|
||||
|
||||
|
||||
Vendored
-46
@@ -1,46 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains1(element: T): Boolean = null!!
|
||||
|
||||
class In<in T>
|
||||
|
||||
class Out<out T>
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun test_1(list: List<In<Number>>, x: In<Number>, y: In<Int>, z: In<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
|
||||
fun test_2(list: List<In<Int>>, x: In<Int>, y: In<Number>, z: In<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
|
||||
fun test_3(list: List<Out<Number>>, x: Out<Number>, y: Out<Int>, z: Out<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
|
||||
fun test_4(list: List<Out<Int>>, x: Out<Int>, y: Out<Number>, z: Out<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
|
||||
fun test_5(list: List<Inv<Number>>, x: Inv<Number>, y: Inv<Int>, z: Inv<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
|
||||
fun test_6(list: List<Inv<Int>>, x: Inv<Int>, y: Inv<Number>, z: Inv<Any>) {
|
||||
list.contains1(x)
|
||||
list.contains1(y)
|
||||
list.contains1(z)
|
||||
}
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@ public fun <K, V> Map<K, V>.get1(key: Any?): Int = null!!
|
||||
public fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get1(key: K): V? = null!!
|
||||
|
||||
fun test(map: Map<Int, String>) {
|
||||
val a: Int = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>listOf(1).contains1("")<!>
|
||||
val a: Int = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>listOf(1).<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>contains1<!>("")<!>
|
||||
val b: Boolean = listOf(1).contains1(1)
|
||||
|
||||
val c: String? = map.get1("")
|
||||
val c: String? = map.<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>get1<!>("")
|
||||
val d: String? = map.get1(1)
|
||||
}
|
||||
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// Issue: KT-26698
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains1(element: T): Boolean = null!!
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.foo(element: T): T = null!!
|
||||
|
||||
class Inv<T>
|
||||
class Inv2<T, R>
|
||||
|
||||
class In<in T>
|
||||
class Out<out T>
|
||||
|
||||
// -------------------------------------------------------
|
||||
|
||||
fun test_0(x: Inv2<in Number, out Number>, list: List<Inv2<Any, Int>>) {
|
||||
list.foo(x)
|
||||
}
|
||||
|
||||
// ------------------------- Inv -------------------------
|
||||
|
||||
fun test_1(x: Inv<Number>, list: List<Inv<Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_2(x: Inv<Number>, list: List<Inv<Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_3(x: Inv<Number>, list: List<Inv<Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_4(x: Inv<in Number>, list: List<Inv<Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_5(x: Inv<in Number>, list: List<Inv<Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_6(x: Inv<in Number>, list: List<Inv<Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_7(x: Inv<out Number>, list: List<Inv<Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_8(x: Inv<out Number>, list: List<Inv<Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_9(x: Inv<out Number>, list: List<Inv<Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
// ------------------------- In -------------------------
|
||||
|
||||
fun test_11(x: In<Number>, list: List<In<Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_12(x: In<Number>, list: List<In<Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_13(x: In<Number>, list: List<In<Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
// ------------------------- Out -------------------------
|
||||
|
||||
fun test_21(x: Out<Number>, list: List<Out<Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_22(x: Out<Number>, list: List<Out<Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_23(x: Out<Number>, list: List<Out<Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
fun test_31(x: Inv<Number>, list: List<Inv<in Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_32(x: Inv<Number>, list: List<Inv<in Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_33(x: Inv<Number>, list: List<Inv<in Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_34(x: Inv<Number>, list: List<Inv<out Number>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_35(x: Inv<Number>, list: List<Inv<out Int>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
|
||||
fun test_36(x: Inv<Number>, list: List<Inv<out Any>>) {
|
||||
list.contains1(x)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// Issue: KT-26698
|
||||
|
||||
|
||||
+6
-6
@@ -43,11 +43,11 @@ fun testOK(first: First, bound: Bound, second: Second) {
|
||||
}
|
||||
|
||||
fun testFail(first: First, bound: Bound, second: Second) {
|
||||
strictSelect(InvB(first), InvB(bound))
|
||||
strictSelect(Inv(first), Inv(bound))
|
||||
strictSelect(Out(first), Out(second))
|
||||
strictSelect(In(first), In(second))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(InvB(first), InvB(bound))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Inv(first), Inv(bound))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Out(first), Out(second))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(In(first), In(second))
|
||||
strictSelect(InB(first), InB(second))
|
||||
strictSelect(Out(Inv(first)), Out(Inv(second)))
|
||||
strictSelect(In(Inv(first)), In(Inv(second)))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Out(Inv(first)), Out(Inv(second)))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(In(Inv(first)), In(Inv(second)))
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@ class First : Common
|
||||
class Second : Common
|
||||
|
||||
fun test(first: First, second: Second) {
|
||||
select(first, second)
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>select<!>(first, second)
|
||||
}
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
//!DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
fun <@kotlin.internal.OnlyInputTypes T> assertEquals1(t1: T, t2: T) {}
|
||||
|
||||
open class A
|
||||
class B: A()
|
||||
class C: A()
|
||||
class D
|
||||
|
||||
fun test1(a: A, b: B, c: C) {
|
||||
assertEquals1(a, b)
|
||||
assertEquals1(b, c)
|
||||
|
||||
assertEquals1(3, 3)
|
||||
assertEquals1(1 or 2, 2 or 1)
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public fun <@kotlin.internal.OnlyInputTypes T> expect1(expected: T, block: () -> T) {}
|
||||
|
||||
fun test() {
|
||||
expect1(2) { byteArrayOf(1, 2, 3).indexOf(3) }
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//!DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
Reference in New Issue
Block a user