Kapt: asMemberOf() should also check the containing type itself, not only its supertypes (KT-13823)
(cherry picked from commit 9f9ffdf)
This commit is contained in:
committed by
Yan Zhulanow
parent
cb9dc21649
commit
415acfbd05
+7
-2
@@ -250,9 +250,14 @@ class KotlinTypes(
|
|||||||
val containingType = containing.psiType
|
val containingType = containing.psiType
|
||||||
|
|
||||||
val member = (element as JeElement).psi as? PsiMember ?: return element.asType()
|
val member = (element as JeElement).psi as? PsiMember ?: return element.asType()
|
||||||
val methodContainingClass = member.containingClass ?: return element.asType()
|
val memberContainingClass = member.containingClass ?: return element.asType()
|
||||||
|
|
||||||
|
val relevantSuperType = if (memberContainingClass == containingType.resolve()) {
|
||||||
|
containingType
|
||||||
|
} else {
|
||||||
|
containingType.superTypes.findSuperType(memberContainingClass) ?: return element.asType()
|
||||||
|
}
|
||||||
|
|
||||||
val relevantSuperType = containingType.superTypes.findSuperType(methodContainingClass) ?: return element.asType()
|
|
||||||
val resolveResult = relevantSuperType.resolveGenerics()
|
val resolveResult = relevantSuperType.resolveGenerics()
|
||||||
if (!resolveResult.isValidResult) return element.asType()
|
if (!resolveResult.isValidResult) return element.asType()
|
||||||
val substitutor = resolveResult.substitutor
|
val substitutor = resolveResult.substitutor
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ open class Base<T> {
|
|||||||
fun m(t: T): T = null!!
|
fun m(t: T): T = null!!
|
||||||
}
|
}
|
||||||
|
|
||||||
class Impl<T> : Base<T>()
|
class Impl<T> : Base<T>() {
|
||||||
|
fun implM(t: T): T = null!!
|
||||||
|
}
|
||||||
|
|
||||||
annotation class Anno
|
annotation class Anno
|
||||||
|
|
||||||
|
|||||||
+5
@@ -263,8 +263,10 @@ class ProcessorTests : AbstractProcessorTest() {
|
|||||||
val fType = f.asType() as JeDeclaredType
|
val fType = f.asType() as JeDeclaredType
|
||||||
|
|
||||||
val base = env.findClass("Base")
|
val base = env.findClass("Base")
|
||||||
|
val impl = env.findClass("Impl")
|
||||||
val baseF = base.findField("f")
|
val baseF = base.findField("f")
|
||||||
val baseM = base.findMethod("m", "T")
|
val baseM = base.findMethod("m", "T")
|
||||||
|
val implM = impl.findMethod("implM", "T")
|
||||||
|
|
||||||
fun check(element: Element, expectedTypeSignature: String) {
|
fun check(element: Element, expectedTypeSignature: String) {
|
||||||
assertEquals(expectedTypeSignature, env.typeUtils.asMemberOf(fType, element).toString())
|
assertEquals(expectedTypeSignature, env.typeUtils.asMemberOf(fType, element).toString())
|
||||||
@@ -275,6 +277,9 @@ class ProcessorTests : AbstractProcessorTest() {
|
|||||||
|
|
||||||
assertEquals("T", baseF.asType().toString())
|
assertEquals("T", baseF.asType().toString())
|
||||||
check(baseF, "java.lang.String")
|
check(baseF, "java.lang.String")
|
||||||
|
|
||||||
|
assertEquals("(T)T", implM.asType().toString())
|
||||||
|
check(implM, "(java.lang.String)java.lang.String")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testDispose() {
|
fun testDispose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user