Skip to content

Commit e7fb6d1

Browse files
committed
expand lowerbound when checking type arguments for flexible types
1 parent 88b78d4 commit e7fb6d1

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ internal fun KtType.classifierSymbol(): KtClassifierSymbol? {
349349
}
350350

351351
internal fun KtType.typeArguments(): List<KtTypeProjection> {
352-
return (this as? KtNonErrorClassType)?.qualifiers?.reversed()?.flatMap { it.typeArguments } ?: emptyList()
352+
return if (this is KtFlexibleType) {
353+
this.lowerBound
354+
} else {
355+
this
356+
}.let { (it as? KtNonErrorClassType)?.qualifiers?.reversed()?.flatMap { it.typeArguments } ?: emptyList() }
353357
}
354358

355359
internal fun KSAnnotated.findAnnotationFromUseSiteTarget(): Sequence<KSAnnotation> {

kotlin-analysis-api/testData/replaceWithErrorTypeArgs.kt

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
// KLE.E.asType(emptyList()): KLE
101101
// default type:A
102102
// flexible type star:T
103+
// flexible type replace argument:JS1<Int>
103104
// END
104105

105106
// MODULE: lib
@@ -123,6 +124,10 @@ class JS<T1, T2> {}
123124
class JS1<T> {
124125
T p;
125126
}
127+
128+
class JavaClass {
129+
JS1<?> p;
130+
}
126131
enum JSE {
127132
E
128133
}
@@ -137,3 +142,4 @@ enum class KSE {
137142

138143
val x: KS<Int, String> = TODO()
139144
val y: KS<NotExist1, NotExist2> = TODO()
145+
val z: KL1<Int> = TODO()

test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ReplaceWithErrorTypeArgsProcessor.kt

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ open class ReplaceWithErrorTypeArgsProcessor : AbstractTestProcessor() {
5050
val xargs = x.type.element!!.typeArguments
5151
val y = resolver.getPropertyDeclarationByName(resolver.getKSNameFromString("y"), true)!!
5252
val yargs = y.type.element!!.typeArguments
53+
val z = resolver.getPropertyDeclarationByName(resolver.getKSNameFromString("z"), true)!!
54+
val zargs = z.type.element!!.typeArguments
5355

5456
for (decl in decls) {
5557
val declName = decl.qualifiedName!!.asString()
@@ -64,6 +66,9 @@ open class ReplaceWithErrorTypeArgsProcessor : AbstractTestProcessor() {
6466
// TODO: fix flexible type creation once upstream available.
6567
val js1 = resolver.getClassDeclarationByName("JS1")!!
6668
results.add("flexible type star:${js1.getDeclaredProperties().single().type.resolve().starProjection()}")
69+
val javaClass = resolver.getClassDeclarationByName("JavaClass")!!
70+
val genericFlexibleProperty = javaClass.getDeclaredProperties().single().type.resolve()
71+
results.add("flexible type replace argument:${genericFlexibleProperty.replace(zargs)}")
6772
return emptyList()
6873
}
6974

test-utils/testData/api/replaceWithErrorTypeArgs.kt

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
// KLE.E.asType(emptyList()): KLE.E
101101
// default type:A
102102
// flexible type star:(T..T?)
103+
// flexible type replace argument:(JS1<Int>..JS1<Int>?)
103104
// END
104105

105106
// MODULE: lib
@@ -123,6 +124,10 @@ class JS<T1, T2> {}
123124
class JS1<T> {
124125
T p;
125126
}
127+
128+
class JavaClass {
129+
JS1<?> p;
130+
}
126131
enum JSE {
127132
E
128133
}
@@ -137,3 +142,4 @@ enum class KSE {
137142

138143
val x: KS<Int, String> = TODO()
139144
val y: KS<NotExist1, NotExist2> = TODO()
145+
val z: KL1<Int> = TODO()

0 commit comments

Comments
 (0)