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:
committed by
Space Team
parent
eab5164993
commit
0c5b700523
+1
-1
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user