[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,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
abstract class A {
abstract val a: Int by Delegate()
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class B {
val a: Int by Delegate()
fun foo() =<!SYNTAX!><!> <!SYNTAX!>$a<!>
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by Delegate()
get
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,14 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
var a: Int by Delegate()
private set
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {}
}
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
interface A {
val prop: Int
}
class AImpl: A {
override val prop by Delegate()
}
fun foo() {
AImpl().prop
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
interface A {
val prop: Int
}
class AImpl: A {
override val prop by Delegate()
}
fun foo() {
AImpl().prop
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
return ""
}
}
@@ -0,0 +1,7 @@
import kotlin.reflect.KProperty0
val a: Int by A()
class A {
fun getValue(t: Any?, p: KProperty0<*>): Int = 1
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by A(1)
class A<T: Any>(i: T) {
operator fun getValue(t: Any?, p: KProperty<*>): T {
throw Exception()
}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
open class Base
class Derived: Base()
val a: Base by A()
class A {
operator fun getValue(t: Any?, p: KProperty<*>): Derived {
return Derived()
}
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
interface T {
val a: Int by Delegate()
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A
class D {
val c: Int by IncorrectThis<A>()
}
val cTopLevel: Int by IncorrectThis<A>()
class IncorrectThis<T> {
fun <R> get(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class Inv2<T, K>
fun <T, K> create(g: (T) -> K): Inv2<T, K> = TODO()
operator fun <S1, V1> Inv2<S1, V1>.getValue(o: Sample, desc: KProperty<*>): V1 = TODO()
operator fun <S2, V2> Inv2<S2, V2>.setValue(o: Sample, desc: KProperty<*>, value: V2) {}
class Version(val version: Int)
class Sample {
var version: Version by create(::Version)
}
@@ -0,0 +1,22 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER
import kotlin.reflect.KProperty
fun test(i: Int) {
val bad by myLazyDelegate {
createSample(i) { it.toString() }
}
<!INAPPLICABLE_CANDIDATE!>takeSample<!>(bad)
}
fun <T> myLazyDelegate(i: () -> T): LazyDelegate<T> = LazyDelegate(i())
class LazyDelegate<T>(val v: T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO()
}
class Sample<K, V>
fun takeSample(g: Sample<Int, String>) {}
fun <T, S> createSample(i: T, a: (T) -> S): Sample<T, S> = TODO()
@@ -0,0 +1,53 @@
// !WITH_NEW_INFERENCE
package baz
import kotlin.reflect.KProperty
class A(outer: Outer) {
var i: String by + getMyConcreteProperty()
var d: String by getMyConcreteProperty() - 1
var c: String by O.getMyProperty()
var g: String by outer.getContainer().getMyProperty()
var b: String by foo(getMyProperty())
var r: String by foo(outer.getContainer().getMyProperty())
var e: String by + foo(getMyProperty())
var f: String by foo(getMyProperty()) - 1
}
fun <A, B> foo(a: Any?) = MyProperty<A, B>()
fun <A, B> getMyProperty() = MyProperty<A, B>()
fun getMyConcreteProperty() = MyProperty<Any?, String>()
class MyProperty<R, T> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
return null as T
}
operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) {
println("set $thisRef ${desc.name} $value")
}
}
operator fun <R, T> MyProperty<R, T>.unaryPlus() = MyProperty<R, T>()
operator fun <R, T> MyProperty<R, T>.minus(i: Int) = MyProperty<R, T>()
object O {
fun <A, B> getMyProperty() = MyProperty<A, B>()
}
interface MyPropertyContainer {
fun <R, T> getMyProperty(): MyProperty<R, T>
}
interface Outer {
fun getContainer(): MyPropertyContainer
}
// -----------------
fun println(a: Any?) = a
@@ -0,0 +1,35 @@
package foo
import kotlin.reflect.KProperty
class A1 {
val a: String by MyProperty1()
}
class MyProperty1 {}
operator fun MyProperty1.getValue(thisRef: Any?, desc: KProperty<*>): String {
throw Exception("$thisRef $desc")
}
//--------------------
class A2 {
val a: String by MyProperty2()
}
class MyProperty2<T> {}
operator fun <T> MyProperty2<T>.getValue(thisRef: Any?, desc: KProperty<*>): T {
throw Exception("$thisRef $desc")
}
//--------------------
class A3 {
val a: String by MyProperty3()
class MyProperty3<T> {}
operator fun <T> MyProperty3<T>.getValue(thisRef: Any?, desc: KProperty<*>): T {
throw Exception("$thisRef $desc")
}
}
@@ -0,0 +1,22 @@
// !WITH_NEW_INFERENCE
package foo
import kotlin.reflect.KProperty
open class A {
val B.w: Int by MyProperty()
}
val B.r: Int by MyProperty()
val A.e: Int by MyProperty()
class B {
val A.f: Int by MyProperty()
}
class MyProperty<R : A, T> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
throw Exception("$thisRef $desc")
}
}
@@ -0,0 +1,28 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A<R>() {
operator fun <T> getValue(t: Any?, p: KProperty<*>): T = null!!
operator fun <T> setValue(t: Any?, p: KProperty<*>, x: T) = Unit
}
var a1: Int by A()
var a2: Int by A<String>()
class B<R>() {
operator fun <T> getValue(t: Any?, p: KProperty<*>): T = null!!
operator fun setValue(t: Any?, p: KProperty<*>, x: R) = Unit
}
var b1: Int by B()
var b2: Int by B<Number>()
class C<R>() {
operator fun getValue(t: Any?, p: KProperty<*>): R = null!!
operator fun <T> setValue(t: Any?, p: KProperty<*>, x: T) = Unit
}
var c1: Int by C()
var c2: Int by C<Number>()
@@ -0,0 +1,27 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
var a: Int by A()
var a1 by A()
var b: Int by B()
val cObj = C()
var c: String by cObj
class A {
operator fun <T> getValue(t: Any?, p: KProperty<*>): T = null!!
operator fun <T> setValue(t: Any?, p: KProperty<*>, x: T) = Unit
}
class B
operator fun <T> B.getValue(t: Any?, p: KProperty<*>): T = null!!
operator fun <T> B.setValue(t: Any?, p: KProperty<*>, x: T) = Unit
class C
operator inline fun <reified T> C.getValue(t: Any?, p: KProperty<*>): T = null!!
operator inline fun <reified T> C.setValue(t: Any?, p: KProperty<*>, x: T) = Unit
@@ -0,0 +1,11 @@
import kotlin.reflect.KProperty
class A3 {
val a: String by l@ MyProperty()
class MyProperty<T> {}
operator fun <T> MyProperty<T>.getValue(thisRef: Any?, desc: KProperty<*>): T {
throw Exception("$thisRef $desc")
}
}
@@ -0,0 +1,26 @@
// !WITH_NEW_INFERENCE
// FILE: main.kt
package test
import first.*
import second.*
val a12 by A()
// FILE: first.kt
package first
import kotlin.reflect.KProperty
class A
public operator fun <T> A.getValue(thisRef: Any?, property: KProperty<*>): T = null!!
// FILE: second.kt
package second
import first.A
import kotlin.reflect.KProperty
public operator fun <T> A.getValue(thisRef: Any?, property: KProperty<*>): T = null!!
@@ -0,0 +1,45 @@
// !WITH_NEW_INFERENCE
package foo
import kotlin.reflect.KProperty
class A {
var a5: String by MyProperty1()
var b5: String by getMyProperty1()
}
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<T, R> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
throw Exception()
}
operator fun setValue(i: Int, j: Any, k: Int) {
println("set")
}
}
// -----------------
class B {
var a5: String by MyProperty2()
var b5: String by getMyProperty2()
}
fun <A, B> getMyProperty2() = MyProperty2<A, B>()
class MyProperty2<T, R> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
throw Exception()
}
operator fun setValue(i: Int) {
println("set")
}
}
// -----------------
fun println(a: Any?) = a
@@ -0,0 +1,18 @@
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
class A {
var a by MyProperty()
}
class MyProperty<T, R> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
throw Exception("$thisRef $desc")
}
operator fun setValue(thisRef: R, desc: KProperty<*>, t: T) {
throw Exception("$thisRef $desc $t")
}
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A<E>
class B<E, F>
fun <K, V> A<K>.toB(f: (V) -> K, g: (K) -> V): B<K, V> = B()
operator fun <T1, E1> B<T1, E1>.getValue(o: Any, desc: KProperty<*>): E1 = TODO()
operator fun <T2, E2> B<T2, E2>.setValue(o: Any, desc: KProperty<*>, value: E2) {}
val q = A<String>()
class Test {
var prop by q.toB({ "abc" }, { "cde" })
}
@@ -0,0 +1,29 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val b: First by lazy {
object : First { }
}
private val withoutType by lazy {
object : First { }
}
private val withTwoSupertypes by lazy {
object : First, Second { }
}
class A<T> {
val a: First by lazy {
object : First { }
}
}
interface First
interface Second
fun <T> lazy(initializer: () -> T): Lazy<T> = TODO()
interface Lazy<out T> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO()
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
import kotlin.reflect.KProperty
class A {
val a by MyProperty()
fun test() {
checkSubtype<Int>(a)
}
}
class MyProperty<R> {
operator fun getValue(thisRef: R, desc: KProperty<*>): Int = throw Exception("$thisRef $desc")
}
@@ -0,0 +1,76 @@
package foo
import kotlin.reflect.KProperty
class A1 {
var a1: String by MyProperty1()
var b1: String by getMyProperty1()
}
var c1: String by getMyProperty1()
var d1: String by MyProperty1()
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<R, T> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
throw Exception()
}
operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) {
println("set $thisRef ${desc.name} $value")
}
}
//--------------------------
class A2 {
var a2: String by MyProperty2()
var b2: String by getMyProperty2()
}
var c2: String by getMyProperty2()
var d2: String by MyProperty2()
fun <A> getMyProperty2() = MyProperty2<A>()
class MyProperty2<T> {
operator fun getValue(thisRef: Any?, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
throw Exception()
}
operator fun setValue(thisRef: Any?, desc: KProperty<*>, value: T) {
println("set $thisRef ${desc.name} $value")
}
}
//--------------------------
class A3 {
var a3: String by MyProperty3()
var b3: String by getMyProperty3()
}
var c3: String by getMyProperty3()
var d3: String by MyProperty3()
fun <A> getMyProperty3() = MyProperty3<A>()
class MyProperty3<T> {
operator fun getValue(thisRef: T, desc: KProperty<*>): String {
println("get $thisRef ${desc.name}")
return ""
}
operator fun setValue(thisRef: Any?, desc: KProperty<*>, value: T) {
println("set $thisRef ${desc.name} $value")
}
}
//--------------------------
fun println(a: Any?) = a
@@ -0,0 +1,64 @@
package foo
import kotlin.reflect.KProperty
class A1 {
val a1: String by MyProperty1()
val b1: String by getMyProperty1()
}
val c1: String by getMyProperty1()
val d1: String by MyProperty1()
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<R, T> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
throw Exception()
}
}
//--------------------------
class A2 {
val a2: String by MyProperty2()
val b2: String by getMyProperty2()
}
val c2: String by getMyProperty2()
val d2: String by MyProperty2()
fun <A> getMyProperty2() = MyProperty2<A>()
class MyProperty2<T> {
operator fun getValue(thisRef: Any?, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
throw Exception()
}
}
//--------------------------
class A3 {
val a3: String by MyProperty3()
val b3: String by getMyProperty3()
}
val c3: String by getMyProperty3()
val d3: String by MyProperty3()
fun <A> getMyProperty3() = MyProperty3<A>()
class MyProperty3<T> {
operator fun getValue(thisRef: T, desc: KProperty<*>): String {
println("get $thisRef ${desc.name}")
return ""
}
}
//--------------------------
fun println(a: Any?) = a
@@ -0,0 +1,11 @@
//KT-4640 "Trace is erased after resolution completion" exception
class ValueWrapper()
{
var backingValue: Int = 0
fun getValue() = backingValue
fun setValue(v: Int) { backingValue = v }
}
val foo by ValueWrapper()
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
import kotlin.reflect.KProperty
class Local {
fun foo() {
val a: Int by Delegate()
}
}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface A {
operator fun getValue(x: Any?, y: Any?): Any?
}
interface B : A {
override fun getValue(x: Any?, y: Any?): Int
}
fun test(a: A) {
if (a is B) {
val x: Int by a
}
}
@@ -0,0 +1,3 @@
val a: Int by A()
class A
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
var a: Int by A()
class A {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,12 @@
// KT-11809 Assertion error when delegated property has getter
class A {
val p1 by this
get
var p2 by this
get() = ""
operator fun getValue(a: Any?, p: Any?) = ""
operator fun setValue(a: Any?, p: Any?, v: Any?) {}
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
class B {
val c by <!INAPPLICABLE_CANDIDATE!>Delegate<!>(<!UNRESOLVED_REFERENCE!>ag<!>)
}
class Delegate<T: Any>(val init: T) {
operator fun getValue(t: Any?, p: KProperty<*>): Int = null!!
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
object CommonCase {
interface Fas<D, E, R>
fun <D, E, R> delegate() : Fas<D, E, R> = TODO()
operator fun <D, E, R> Fas<D, E, R>.provideDelegate(host: D, p: Any?): Fas<D, E, R> = TODO()
operator fun <D, E, R> Fas<D, E, R>.getValue(receiver: E, p: Any?): R = TODO()
val Long.test1: String by delegate() // common test, not working because of Inference1
val Long.test2: String by delegate<CommonCase, Long, String>() // should work
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Cell<out V>(val value: V)
class GenericDelegate<V>(val value: V)
operator fun <T> T.provideDelegate(a: Any?, p: Any?) = GenericDelegate(this)
operator fun <W> GenericDelegate<W>.getValue(a: Any?, p: Any?) = Cell(value)
val test1: Cell<String> by "OK"
val test2: Cell<Any> by "OK"
val test3 by "OK"
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
object T1 {
operator fun Int.provideDelegate(host: T1, p: Any): Long = 2
operator fun Long.getValue(receiver: String, p: Any): Double = 1.0
val String.test1 by 1
val test2 by 1
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
object T2 {
interface Foo<T>
fun <T> delegate(): Foo<T> = TODO()
operator fun <T> Foo<T>.provideDelegate(host: T2, p: Any?): Foo<T> = TODO()
operator fun <T> Foo<T>.getValue(receiver: String, p: Any?): T = TODO()
val String.test1: String by delegate()
val test2: String by delegate()
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
object T3 {
interface Foo<T>
fun <T> delegate(): Foo<T> = TODO()
operator fun <T> Foo<T>.provideDelegate(host: T3, p: Any?): Foo<T> = TODO()
operator fun <T> Foo<T>.getValue(receiver: T3, p: Any?): T = TODO()
val test1: String by delegate()
}
@@ -0,0 +1,15 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
object Inference1 {
interface Foo<T>
fun <T> delegate(): Foo<T> = TODO()
operator fun <T> Foo<T>.getValue(receiver: T, p: Any?): String = TODO()
// not working because resulting descriptor for getValue contains type `???` instead of `T`
val test1: String by delegate()
val test2: String by delegate<Inference1>()
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
object Inference2 {
interface Foo<T>
fun <T> delegate(): Foo<T> = TODO()
operator fun <T> Foo<T>.provideDelegate(host: T, p: Any?): Foo<T> = TODO()
operator fun <T> Foo<T>.getValue(receiver: Inference2, p: Any?): String = TODO()
val test1: String by delegate() // same story like in Inference1
val test2: String by delegate<Inference2>()
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
operator fun String.provideDelegate(a: Any?, p: KProperty<*>) = this
operator fun String.getValue(a: Any?, p: KProperty<*>) = this
fun test(): String {
val result by "OK"
return result
}
@@ -0,0 +1,18 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class StringDelegate(val s: String) {
operator fun getValue(a: Any?, p: KProperty<*>): Int = 42
}
// NB no operator
fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this)
operator fun String.getValue(a: Any?, p: KProperty<*>) = this
val test1: String by "OK"
val test2: Int by "OK"
val test3 by "OK"
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.reflect.KProperty
object Foo
object Bar
object Baz
operator fun Foo.provideDelegate(receiver: Any?, property: KProperty<*>) = this
operator fun Bar.provideDelegate(receiver: Any?, property: KProperty<*>) = this
operator fun Foo.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
operator fun Bar.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
operator fun Baz.getValue(nothing: Any?, property: KProperty<*>): Any = TODO()
fun test() {
val bar by Baz
}
@@ -0,0 +1,32 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
operator fun provideDelegate(x: Any?, p: KProperty<*>) {}
operator fun Any.provideDelegate(x: Any?, p: KProperty<*>) {}
operator fun Any.provideDelegate(x: Any?, p: Any) {}
operator fun Any.provideDelegate(x: Any?, p: Int) {}
class Host1 {
operator fun provideDelegate(x: Any?, p: KProperty<*>) {}
}
class Host2 {
operator fun Any.provideDelegate(x: Any?, p: KProperty<*>) {}
}
class Host3 {
operator fun provideDelegate(x: Any?, p: KProperty<*>, foo: Int) {}
}
class Host4 {
operator fun provideDelegate(x: Any?, p: KProperty<*>, foo: Int = 0) {}
}
class Host5 {
operator fun provideDelegate(x: Any?, p: KProperty<*>, vararg foo: Int) {}
}
@@ -0,0 +1,17 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Delegate<T>
operator fun Delegate<*>.getValue(receiver: Any?, p: Any): String = ""
operator fun <T> Delegate<T>.setValue(receiver: Any?, p: Any, value: T) {}
operator fun <T> String.provideDelegate(receiver: Any?, p: Any) = Delegate<T>()
var test1: String by Delegate()
var test2: String by Delegate<String>()
var test3: String by "OK"
var test4: String by "OK".provideDelegate(null, "")
var test5: String by "OK".provideDelegate<String>(null, "")
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
operator fun String.provideDelegate(a: Any?, p: KProperty<*>) = this
operator fun String.getValue(a: Any?, p: KProperty<*>) = this
val test1: String by "OK"
val test2 by "OK"
@@ -0,0 +1,15 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: -OperatorProvideDelegate
class WrongDelegate(val x: Int) {
operator fun getValue(thisRef: Any?, prop: Any): Int = x
}
operator fun String.provideDelegate(thisRef: Any?, prop: Any) = WrongDelegate(this.length)
operator fun String.getValue(thisRef: Any?, prop: Any) = this
val test1: String by "OK"
val test2: Int by "OK"
val test3 by "OK"
@@ -0,0 +1,18 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
val a by a
val b by Delegate(b)
val c by d
val d by c
class Delegate(i: Int) {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val a: Int by Delegate()
get() = 1
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
var a: Int by Delegate()
get() = 1
set(i) {}
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {}
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class D {
var c: Int by Delegate()
}
var cTopLevel: Int by Delegate()
class A
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: A, p: KProperty<*>, i: Int) {}
}
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
open class Base
class Derived: Base()
var a: Derived by A()
class A {
operator fun getValue(t: Any?, p: KProperty<*>): Derived {
return Derived()
}
operator fun setValue(t: Any?, p: KProperty<*>, i: Base) {}
}
@@ -0,0 +1,13 @@
import kotlin.reflect.KProperty
class A
object Delegate {
operator fun getValue(state: A, desc: KProperty<*>): Int = 0
operator fun setValue(state: A, desc: KProperty<*>, value: Int) {}
}
open class B {
val A.foo: Int by Delegate
var A.bar: Int by Delegate
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val Int.a by Delegate(this)
class A {
val Int.a by <!INAPPLICABLE_CANDIDATE!>Delegate<!>(this)
}
class Delegate(i: Int) {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
var a: Int by Delegate()
}
var aTopLevel: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, a: Int) {}
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
class A {
var a: Int by Delegate()
}
var aTopLevel: Int by Delegate()
class Delegate {
operator fun getValue(t: Nothing?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Nothing?, p: KProperty<*>, a: Int) {
}
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
class A {
var a: Int by Delegate()
}
var aTopLevel: Int by Delegate()
class Delegate {
fun getValue(t: Nothing, p: KProperty<*>): Int {
return 1
}
fun setValue(t: Nothing, p: KProperty<*>, a: Int) {
}
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
val c: Int by Delegate()
}
class Delegate {
fun getValue(t: Int, p: KProperty<*>): Int {
return 1
}
fun getValue(t: String, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,12 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
val c: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
return ""
}
}
@@ -0,0 +1,23 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A
class B {
val b: Int by Delegate<A>()
}
val bTopLevel: Int by Delegate<A>()
class C {
val c: Int by Delegate<C>()
}
val cTopLevel: Int by Delegate<Nothing?>()
class Delegate<T> {
operator fun getValue(t: T, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
var a: Int by Delegate()
}
var aTopLevel: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, i: String) {}
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
class B {
val b: Int by Delegate()
}
val bTopLevel: Int by Delegate()
class A
class Delegate {
fun getValue(t: A, p: KProperty<*>): Int {
return 1
}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
val a: Int by Delegate()
}
val aTopLevel: Int by Delegate()
class Delegate {
fun getValue(t: Any?, p: KProperty<*>, a: Int): Int {
return a
}
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
class A {
var a: Int by Delegate()
}
var aTopLevel: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, a: Int, c: Int) {}
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty
var b: Int by Delegate()
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
operator fun setValue(t: Any?, p: KProperty<*>, i: Int): Int {
return i
}
}