Skip to content

Commit 36252be

Browse files
ting-yuanKSP Auto Pick
authored andcommitted
KSTypeArgumentResolvedImpl: use aliasing type
instead of aliased type. This aligns with KSTypeReference.resolve() which doesn't expand typealiases. (cherry picked from commit a977fb9)
1 parent f1057e6 commit 36252be

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.google.devtools.ksp.impl.symbol.kotlin.Restorable
2424
import com.google.devtools.ksp.impl.symbol.kotlin.annotations
2525
import com.google.devtools.ksp.symbol.*
2626
import org.jetbrains.kotlin.analysis.api.types.KaStarTypeProjection
27+
import org.jetbrains.kotlin.analysis.api.types.KaType
2728
import org.jetbrains.kotlin.analysis.api.types.KaTypeArgumentWithVariance
2829
import org.jetbrains.kotlin.analysis.api.types.KaTypeProjection
2930

@@ -50,12 +51,16 @@ class KSTypeArgumentResolvedImpl private constructor(
5051
}
5152
}
5253

54+
private val kaType: KaType? by lazy {
55+
ktTypeProjection.type?.abbreviation ?: ktTypeProjection.type
56+
}
57+
5358
override val type: KSTypeReference? by lazy {
54-
ktTypeProjection.type?.let { KSTypeReferenceResolvedImpl.getCached(it, this@KSTypeArgumentResolvedImpl) }
59+
kaType?.let { KSTypeReferenceResolvedImpl.getCached(it, this@KSTypeArgumentResolvedImpl) }
5560
}
5661

5762
override val annotations: Sequence<KSAnnotation> by lazy {
58-
ktTypeProjection.type?.annotations(this) ?: emptySequence()
63+
kaType?.annotations(this) ?: emptySequence()
5964
}
6065

6166
override val origin: Origin = parent?.origin ?: Origin.SYNTHETIC

kotlin-analysis-api/testData/typeAlias.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// myList_b_String : MyList_B_String = MyList_B<String> = MyList<R> = List<T>
3232
// myListOfAlias : MyListOfAlias = List<@JvmSuppressWildcards A>
3333
// myListOfAliasInLib : MyListOfAliasInLib = List<@JvmSuppressWildcards AInLib>
34+
// viewBinderProviders : Map<Class<BaseViewHolder>, @JvmSuppressWildcards Provider<BaseEmbedViewBinder>>
35+
// nested1 : MyList<ListOfInt> = List<T>
36+
// nested2 : List<ListOfInt>
3437
// END
3538

3639
// MODULE: module1
@@ -65,3 +68,13 @@ val myList_String: MyList_String = TODO()
6568
val myList_b_String: MyList_B_String = TODO()
6669
val myListOfAlias: MyListOfAlias = TODO()
6770
val myListOfAliasInLib: MyListOfAliasInLib = TODO()
71+
72+
interface BaseViewHolder
73+
interface SpaceshipEmbedModel
74+
interface Provider<T>
75+
interface ViewBinder<T1, T2>
76+
typealias BaseEmbedViewBinder = ViewBinder<out BaseViewHolder, out SpaceshipEmbedModel>
77+
78+
val viewBinderProviders: Map<Class<out BaseViewHolder>, @JvmSuppressWildcards Provider<BaseEmbedViewBinder>> = TODO()
79+
val nested1: MyList<ListOfInt>
80+
val nested2: List<ListOfInt>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ open class TypeAliasProcessor : AbstractTestProcessor() {
7878
append(declaration.simpleName.asString())
7979
if (arguments.isNotEmpty()) {
8080
append("<")
81-
arguments.map {
82-
it.type?.resolve()?.toSignature() ?: "<error>"
81+
arguments.mapIndexed { i, arg ->
82+
val s = arg.type?.resolve()?.toSignature() ?: "<error>"
83+
if (i < arguments.size - 1)
84+
s + ", "
85+
else
86+
s
8387
}.forEach(this::append)
8488
append(">")
8589
}

test-utils/testData/api/typeAlias.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// myList_b_String : MyList_B_String = MyList_B<String> = MyList<R> = List<T>
3232
// myListOfAlias : MyListOfAlias = List<A>
3333
// myListOfAliasInLib : MyListOfAliasInLib = List<@JvmSuppressWildcards AInLib>
34+
// viewBinderProviders : Map<Class<BaseViewHolder>, @JvmSuppressWildcards Provider<BaseEmbedViewBinder>>
35+
// nested1 : MyList<ListOfInt> = List<T>
36+
// nested2 : List<ListOfInt>
3437
// END
3538

3639
// MODULE: module1
@@ -66,3 +69,13 @@ val myList_b_String: MyList_B_String = TODO()
6669
// FIXME: type annotation is missing
6770
val myListOfAlias: MyListOfAlias = TODO()
6871
val myListOfAliasInLib: MyListOfAliasInLib = TODO()
72+
73+
interface BaseViewHolder
74+
interface SpaceshipEmbedModel
75+
interface Provider<T>
76+
interface ViewBinder<T1, T2>
77+
typealias BaseEmbedViewBinder = ViewBinder<out BaseViewHolder, out SpaceshipEmbedModel>
78+
79+
val viewBinderProviders: Map<Class<out BaseViewHolder>, @JvmSuppressWildcards Provider<BaseEmbedViewBinder>> = TODO()
80+
val nested1: MyList<ListOfInt>
81+
val nested2: List<ListOfInt>

0 commit comments

Comments
 (0)