Skip to content

Commit

Permalink
asMemberOf: substitude upper and lower bounds recursively
Browse files Browse the repository at this point in the history
for flexible types.

(cherry picked from commit c95b34c)
  • Loading branch information
ting-yuan authored and KSP Auto Pick committed Oct 5, 2024
1 parent d155715 commit 8bdc388
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,11 @@ internal fun KaValueParameterSymbol.getDefaultValue(): KaAnnotationValue? {
internal fun fillInDeepSubstitutor(context: KaType, substitutorBuilder: KaSubstitutorBuilder) {
val unwrappedType = when (context) {
is KaClassType -> context
is KaFlexibleType -> context.lowerBound as? KaClassType ?: return
is KaFlexibleType -> {
fillInDeepSubstitutor(context.upperBound, substitutorBuilder)
fillInDeepSubstitutor(context.lowerBound, substitutorBuilder)
return
}
else -> return
}
val parameters = unwrappedType.symbol.typeParameters
Expand Down
12 changes: 12 additions & 0 deletions kotlin-analysis-api/testData/asMemberOf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
// WITH_RUNTIME
// TEST PROCESSOR: AsMemberOfProcessor
// EXPECTED:
// main.Test: MutableIterator<(String..String?)>
// main.Test: Iterator<(String..String?)>
// main.Test: MutableIterator<(String..String?)>
// lib.Test: MutableIterator<(String..String?)>
// lib.Test: Iterator<(String..String?)>
// lib.Test: MutableIterator<(String..String?)>
// main.TestKt: MutableIterator<String>
// main.TestKt: Iterator<String>
// main.TestKt: MutableIterator<String>
// lib.TestKt: MutableIterator<String>
// lib.TestKt: Iterator<String>
// lib.TestKt: MutableIterator<String>
// Child1!!
// intType: kotlin.Int!!
// baseTypeArg1: kotlin.Int!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ class AsMemberOfProcessor : AbstractTestProcessor() {

listOf("main.Test", "lib.Test", "main.TestKt", "lib.TestKt").forEach { clsName ->
resolver.getClassDeclarationByName(clsName)!!.let { cls ->
val listType = cls.getAllFunctions().single {it.simpleName.asString() == "f"}.returnType!!.resolve()
val listType = cls.getAllFunctions().single { it.simpleName.asString() == "f" }.returnType!!.resolve()
val listDecl = listType.declaration as KSClassDeclaration
val iterator = listDecl.getAllFunctions().single { it.simpleName.asString() == "iterator" }
println("$clsName: ${iterator.asMemberOf(listType).returnType}")
val listIterator = resolver.getClassDeclarationByName("kotlin.collections.List")!!.getDeclaredFunctions().single { it.simpleName.asString() == "iterator" }
println("$clsName: ${listIterator.asMemberOf(listType).returnType}")
val mutableListIterator = resolver.getClassDeclarationByName("kotlin.collections.MutableCollection")!!.getDeclaredFunctions().single { it.simpleName.asString() == "iterator" }
println("$clsName: ${mutableListIterator.asMemberOf(listType).returnType}")
results.add("$clsName: ${iterator.asMemberOf(listType).returnType}")
val listIterator = resolver.getClassDeclarationByName("kotlin.collections.List")!!
.getDeclaredFunctions().single { it.simpleName.asString() == "iterator" }
results.add("$clsName: ${listIterator.asMemberOf(listType).returnType}")
val mutableListIterator =
resolver.getClassDeclarationByName("kotlin.collections.MutableCollection")!!
.getDeclaredFunctions().single { it.simpleName.asString() == "iterator" }
results.add("$clsName: ${mutableListIterator.asMemberOf(listType).returnType}")
}
}

Expand Down
12 changes: 12 additions & 0 deletions test-utils/testData/api/asMemberOf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
// WITH_RUNTIME
// TEST PROCESSOR: AsMemberOfProcessor
// EXPECTED:
// main.Test: MutableIterator<(String..String?)>
// main.Test: Iterator<(String..String?)>
// main.Test: MutableIterator<(String..String?)>
// lib.Test: MutableIterator<(String..String?)>
// lib.Test: Iterator<(String..String?)>
// lib.Test: MutableIterator<(String..String?)>
// main.TestKt: MutableIterator<String>
// main.TestKt: Iterator<String>
// main.TestKt: MutableIterator<String>
// lib.TestKt: MutableIterator<String>
// lib.TestKt: Iterator<String>
// lib.TestKt: MutableIterator<String>
// Child1!!
// intType: kotlin.Int!!
// baseTypeArg1: kotlin.Int!!
Expand Down

0 comments on commit 8bdc388

Please sign in to comment.