Uast: UastFakeLightMethod dependent generic type SOE fix KT-39155

This commit is contained in:
Nicolay Mitropolsky
2020-05-27 16:25:46 +03:00
parent de790a3e3b
commit e60a32e8d3
5 changed files with 83 additions and 16 deletions
@@ -26,15 +26,21 @@ internal class UastFakeLightMethod(original: KtFunction, containingClass: PsiCla
KotlinLightTypeParameterListBuilder(this).also { paramList ->
for ((i, p) in original.typeParameters.withIndex()) {
paramList.addParameter(
LightTypeParameterBuilder(
object : LightTypeParameterBuilder(
p.name ?: "__no_name__",
this,
i
).apply {
p.extendsBound?.getType()
?.toPsiType(this@UastFakeLightMethod, original, false)
?.safeAs<PsiClassType>()
?.let { extendsList.addReference(it) }
) {
private val myExtendsList by lazy {
super.getExtendsList().apply {
p.extendsBound?.getType()
?.toPsiType(this@UastFakeLightMethod, original, false)
?.safeAs<PsiClassType>()
?.let { addReference(it) }
}
}
override fun getExtendsList(): LightReferenceListBuilder = myExtendsList
}
)
}
+16 -1
View File
@@ -10,4 +10,19 @@ private inline fun <reified T> function8(t: T, i: Int, s: String): T = t
internal inline fun <reified T> function9(t: T, i: Int, s: String): T = t
public inline fun <reified T> function10(t: T, i: Int, s: String): T = t
inline fun <reified T> T.function11(t: T, i: Int, s: String): T = t
inline fun <reified T : CharSequence> T.function11CharSequence(t: T, i: Int, s: String): T = t
inline fun <reified T : CharSequence> T.function11CharSequence(t: T, i: Int, s: String): T = t
inline fun <reified T : CharSequence, reified B : T> T.function12CharSequence(t: B, i: T, s: String): B = t
fun <T, B> copyWhenGreater(list: List<T>, threshold: T, threshold2: B): B
where T : CharSequence,
T : Comparable<T>,
B : T {
return threshold2
}
class Foo<T> {
inline fun <reified Z : T> foo(): Z {
TODO()
}
}
+29
View File
@@ -28,6 +28,16 @@ UFile (package = )
UBlockExpression
UReturnExpression
USimpleNameReferenceExpression (identifier = t)
UMethod (name = copyWhenGreater)
UParameter (name = list)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UParameter (name = threshold)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UParameter (name = threshold2)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UBlockExpression
UReturnExpression
USimpleNameReferenceExpression (identifier = threshold2)
UMethod (name = function3)
UParameter (name = t)
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
@@ -132,3 +142,22 @@ UFile (package = )
UBlockExpression
UReturnExpression
USimpleNameReferenceExpression (identifier = t)
UMethod (name = function12CharSequence)
UParameter (name = $this$function12CharSequence)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UParameter (name = t)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UParameter (name = i)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UParameter (name = s)
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
UBlockExpression
UReturnExpression
USimpleNameReferenceExpression (identifier = t)
UClass (name = Foo)
UMethod (name = Foo)
UMethod (name = foo)
UBlockExpression
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
UIdentifier (Identifier (TODO))
USimpleNameReferenceExpression (identifier = TODO, resolvesTo = null)
@@ -7,6 +7,9 @@ public final class ReifiedReturnTypeKt {
public static final fun function2CharSequence(@org.jetbrains.annotations.NotNull t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
return t
}
public static final fun copyWhenGreater(@org.jetbrains.annotations.NotNull list: java.util.List<? extends T>, @org.jetbrains.annotations.NotNull threshold: T, @org.jetbrains.annotations.NotNull threshold2: B) : B {
return threshold2
}
static fun function3(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : void {
}
static fun function4(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
@@ -36,4 +39,14 @@ public final class ReifiedReturnTypeKt {
static fun function11CharSequence(@org.jetbrains.annotations.NotNull $this$function11CharSequence: T, @org.jetbrains.annotations.NotNull t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
return t
}
static fun function12CharSequence(@org.jetbrains.annotations.NotNull $this$function12CharSequence: T, @org.jetbrains.annotations.NotNull t: B, @org.jetbrains.annotations.NotNull i: T, @org.jetbrains.annotations.NotNull s: java.lang.String) : B {
return t
}
}
public final class Foo {
public fun Foo() = UastEmptyExpression
fun foo() : Z {
TODO()
}
}
+13 -9
View File
@@ -1,9 +1,6 @@
package org.jetbrains.uast.test.kotlin
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiModifier
import com.intellij.psi.*
import com.intellij.testFramework.RunAll
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.ThrowableRunnable
@@ -663,6 +660,7 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
function1 -> PsiType:void
function2 -> PsiType:T
function2CharSequence -> PsiType:T extends PsiType:CharSequence
copyWhenGreater -> PsiType:B extends PsiType:T extends PsiType:CharSequence, PsiType:Comparable<? super T>
function3 -> PsiType:void
function4 -> PsiType:T
function5 -> PsiType:int
@@ -673,15 +671,21 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
function10 -> PsiType:T
function11 -> PsiType:T
function11CharSequence -> PsiType:T extends PsiType:CharSequence
function12CharSequence -> PsiType:B extends PsiType:T extends PsiType:CharSequence
Foo -> null
foo -> PsiType:Z extends PsiType:T
""".trimIndent(), methods.joinToString("\n") { m ->
buildString {
append(m.name).append(" -> ")
append(m.returnType)
m.returnType.safeAs<PsiClassType>()?.resolve()?.extendsList?.referencedTypes?.takeIf { it.isNotEmpty() }?.let { e ->
append(" extends ")
append(e.joinToString { it.toString() })
fun PsiType.typeWithExtends(): String = buildString {
append(this@typeWithExtends)
this@typeWithExtends.safeAs<PsiClassType>()?.resolve()?.extendsList?.referencedTypes?.takeIf { it.isNotEmpty() }
?.let { e ->
append(" extends ")
append(e.joinToString(", ") { it.typeWithExtends() })
}
}
append(m.returnType?.typeWithExtends())
}
})
for (method in methods.drop(3)) {