[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,36 @@
// !CHECK_TYPE
import kotlin.reflect.KProperty1
interface Base {
val x: Any
}
class A : Base {
override val x: String = ""
}
open class B : Base {
override val x: Number = 1.0
}
class C : B() {
override val x: Int = 42
}
fun test() {
val base = Base::x
checkSubtype<KProperty1<Base, Any>>(base)
checkSubtype<Any>(base.get(A()))
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Number>(base.get(B()))
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(base.get(C()))
val a = A::x
checkSubtype<KProperty1<A, String>>(a)
checkSubtype<String>(a.get(A()))
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Number>(a.<!INAPPLICABLE_CANDIDATE!>get<!>(B()))
val b = B::x
checkSubtype<KProperty1<B, Number>>(b)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><Int>(b.get(C()))
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
import kotlin.reflect.KProperty1
open class Base {
val foo: Int = 42
}
open class Derived : Base()
fun test() {
val o = Base::foo
checkSubtype<KProperty1<Base, Int>>(o)
checkSubtype<Int>(o.get(Derived()))
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS:-UNUSED_VARIABLE
import kotlin.reflect.*
class A(var g: A) {
val f: Int = 0
fun test() {
val fRef: KProperty1<A, Int> = A::f
val gRef: KMutableProperty1<A, A> = A::g
}
}
@@ -0,0 +1,25 @@
// !CHECK_TYPE
import kotlin.reflect.*
val String.countCharacters: Int
get() = length
var Int.meaning: Long
get() = 42L
set(value) {}
fun test() {
val f = String::countCharacters
checkSubtype<KProperty1<String, Int>>(f)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KMutableProperty1<String, Int>>(f)
checkSubtype<Int>(f.get("abc"))
f.<!UNRESOLVED_REFERENCE!>set<!>("abc", 0)
val g = Int::meaning
checkSubtype<KMutableProperty1<Int, Long>>(g)
checkSubtype<Long>(g.get(0))
g.set(1, 0L)
}
@@ -0,0 +1,10 @@
// !CHECK_TYPE
val Any?.meaning: Int
get() = 42
fun test() {
val f = Any?::meaning
checkSubtype<Int>(f.get(null))
checkSubtype<Int>(f.get(""))
}
@@ -0,0 +1,16 @@
// !CHECK_TYPE
import kotlin.reflect.KProperty1
class A<T>(val t: T) {
val foo: T = t
}
fun bar() {
val x = A<String>::foo
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KProperty1<A<String>, String>>(x)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KProperty1<A<String>, Any?>>(x)
val y = A<*>::foo
checkSubtype<KProperty1<A<*>, Any?>>(y)
}
@@ -0,0 +1,26 @@
// !DIAGNOSTICS:-UNUSED_VARIABLE
// FILE: JavaClass.java
public class JavaClass {
public final int publicFinal;
public long publicMutable;
protected final double protectedFinal;
protected char protectedMutable;
private final String privateFinal;
private Object privateMutable;
}
// FILE: test.kt
import kotlin.reflect.*
fun test() {
val pubFinRef: KProperty1<JavaClass, Int> = JavaClass::publicFinal
val pubMutRef: KMutableProperty1<JavaClass, Long> = JavaClass::publicMutable
val protFinRef: KProperty1<JavaClass, Double> = JavaClass::protectedFinal
val protMutRef: KMutableProperty1<JavaClass, Char> = JavaClass::protectedMutable
val privFinRef: KProperty1<JavaClass, String?> = JavaClass::privateFinal
val privMutRef: KMutableProperty1<JavaClass, Any?> = JavaClass::privateMutable
}
@@ -0,0 +1,28 @@
// !DIAGNOSTICS:-UNUSED_VARIABLE
// FILE: JavaClass.java
public class JavaClass {
public static final String publicFinal;
public static volatile Object publicMutable;
protected static final double protectedFinal;
protected static char protectedMutable;
private static final JavaClass privateFinal;
private static Throwable privateMutable;
}
// FILE: test.kt
import JavaClass.*
import kotlin.reflect.*
fun test() {
val pubFinRef: KProperty0<String> = ::publicFinal
val pubMutRef: KMutableProperty0<Any?> = ::publicMutable
val protFinRef: KProperty<Double> = ::protectedFinal
val protMutRef: KMutableProperty<Char> = ::protectedMutable
val privFinRef: KProperty<JavaClass?> = ::privateFinal
val privMutRef: KMutableProperty<Throwable?> = ::privateMutable
}
@@ -0,0 +1,12 @@
import kotlin.reflect.*
fun <T> checkSubtype(t: T) = t
class A(var g: A) {
val f: Int = 0
fun test() {
checkSubtype<KProperty1<A, Int>>(A::f)
checkSubtype<KMutableProperty1<A, A>>(A::g)
}
}
@@ -0,0 +1,11 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty1
class TestClass(var prop: Int)
open class OtherClass
fun OtherClass.test(prop: KProperty1<TestClass, Int>): Unit = throw Exception()
class OtherClass2: OtherClass() {
val result = <!INAPPLICABLE_CANDIDATE!>test<!>(TestClass::result)
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun eat(value: Any) {}
fun test(param: String) {
val a = ::param
val local = "local"
val b = ::local
val lambda = { -> }
val g = ::lambda
eat(::param)
}
@@ -0,0 +1,25 @@
// !CHECK_TYPE
import kotlin.reflect.*
class A {
val foo: Int = 42
var bar: String = ""
}
fun test() {
val p = A::foo
checkSubtype<KProperty1<A, Int>>(p)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KMutableProperty1<A, Int>>(p)
checkSubtype<Int>(p.get(A()))
p.<!INAPPLICABLE_CANDIDATE!>get<!>()
p.<!UNRESOLVED_REFERENCE!>set<!>(A(), 239)
val q = A::bar
checkSubtype<KProperty1<A, String>>(q)
checkSubtype<KMutableProperty1<A, String>>(q)
checkSubtype<String>(q.get(A()))
q.set(A(), "q")
}
@@ -0,0 +1,22 @@
// KT-12982 Incorrect type inference when accessing mutable protected property via reflection
import kotlin.reflect.KMutableProperty1
class Foo {
protected var x = 0
fun baz(p: KMutableProperty1<Foo, Int>) = p
fun print() = baz(Foo::x)
}
open class A {
protected fun a() {}
}
open class B : A() {
val x = C::a
val y = C()::a
}
class C : B()
@@ -0,0 +1,8 @@
import kotlin.reflect.KProperty1
fun <T, R> getProperty(x: T, property: KProperty1<T, R>): R =
property.get(x)
class Person(val name: String)
val name1 = getProperty(Person("John Smith"), Person::name)
@@ -0,0 +1,13 @@
// !CHECK_TYPE
import kotlin.reflect.KProperty1
class C {
val baz: Int = 12
}
fun Int.baz() {}
fun test() {
C::baz checkType { <!UNRESOLVED_REFERENCE!>_<!><KProperty1<C, Int>>() }
}
@@ -0,0 +1,19 @@
// FILE: Customer.java
public class Customer {
private String name;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
// FILE: test.kt
val customerName = Customer::name
@@ -0,0 +1,32 @@
// !CHECK_TYPE
import kotlin.reflect.*
var x: Int = 42
val y: String get() = "y"
fun testX() {
val xx = ::x
checkSubtype<KMutableProperty0<Int>>(xx)
checkSubtype<KProperty0<Int>>(xx)
checkSubtype<KMutableProperty<Int>>(xx)
checkSubtype<KProperty<Int>>(xx)
checkSubtype<KCallable<Int>>(xx)
checkSubtype<String>(xx.name)
checkSubtype<Int>(xx.get())
xx.set(239)
}
fun testY() {
val yy = ::y
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KMutableProperty0<String>>(yy)
checkSubtype<KProperty0<String>>(yy)
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><KMutableProperty<String>>(yy)
checkSubtype<KProperty<String>>(yy)
checkSubtype<KCallable<String>>(yy)
checkSubtype<String>(yy.name)
checkSubtype<String>(yy.get())
yy.<!UNRESOLVED_REFERENCE!>set<!>("yy")
}