Don't report unused variable warning for delegated variables with provide delegate

^KT-38871 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2023-03-27 11:20:33 +02:00
committed by Space Team
parent 18cfc9fcf1
commit 681e85eaed
9 changed files with 142 additions and 2 deletions
@@ -0,0 +1,27 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: +UNUSED_VARIABLE
import kotlin.reflect.KProperty
class Example {
val valProp: String by Delegate()
val varProp: String by Delegate()
fun foo() {
val valVariable by Delegate()
val varVariable by Delegate()
}
}
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String = "delegation"
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
// setValue
}
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): Delegate {
// side effect
return Delegate()
}
}
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: +UNUSED_VARIABLE
import kotlin.reflect.KProperty
class Example {
val valProp: String by Delegate()
val varProp: String by Delegate()
fun foo() {
val valVariable by Delegate()
val varVariable by Delegate()
}
}
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String = "delegation"
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
// setValue
}
}
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: +UNUSED_VARIABLE
import kotlin.reflect.KProperty
class Example {
val valProp: String by Delegate()
val varProp: String by Delegate()
fun foo() {
val <!UNUSED_VARIABLE!>valVariable<!> by Delegate()
val <!UNUSED_VARIABLE!>varVariable<!> by Delegate()
}
}
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String = "delegation"
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
// setValue
}
}