K2: fix annotation search on supertypes in assignment plugin

Current implementation checks only immediate supertype, while
in case of gradle build scripts DSL, the annotated superclass
is located deeper in the hierarchy.
The fix implements a recursive supertype check.

#KT-65983 fixed
This commit is contained in:
Ilya Chernikov
2024-02-19 09:38:57 +01:00
committed by Space Team
parent eab5164993
commit 0c5b700523
2 changed files with 23 additions and 1 deletions
@@ -43,7 +43,7 @@ internal class FirAssignAnnotationMatchingService(
if (this.annotations.any { it.toAnnotationClassId(session)?.asSingleFqName() in annotationClassIds }) return true
return resolvedSuperTypeRefs.any { superTypeRef ->
val symbol = superTypeRef.type.fullyExpandedType(session).toRegularClassSymbol(session) ?: return@any false
symbol.annotations.any { it.toAnnotationClassId(session)?.asSingleFqName() in annotationClassIds }
symbol.annotated()
}
}
}
+22
View File
@@ -45,6 +45,16 @@ data class KotlinStringProperty(private var v: String): KotlinProperty<String> {
override fun get() = this.v
}
abstract class KotlinAbstractStringProperty: KotlinProperty<String>
data class KotlinStringProperty2(private var v: String): KotlinAbstractStringProperty() {
override fun assign(v: String) {
this.v = v
}
override fun get() = this.v
}
@ValueContainer
data class KotlinClassStringProperty(private var v: String) {
fun assign(v: String) {
@@ -91,6 +101,18 @@ fun `should work with annotation on Kotlin interface`(): String {
}
}
fun `should work with annotation on Kotlin interface via intermediate supertype`(): String {
data class Task(val input: KotlinStringProperty2)
val task = Task(KotlinStringProperty2("Fail"))
task.input = "OK"
return if (task.input.get() != "OK") {
"Fail: ${task.input.get()}"
} else {
"OK"
}
}
fun `should work with annotation on Kotlin class`(): String {
data class Task(val input: KotlinClassStringProperty)
val task = Task(KotlinClassStringProperty("Fail"))