Skip to content

Commit

Permalink
KSP2: Do not expand KSType.declaration for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed Aug 27, 2024
1 parent 9c900f0 commit 1f7b4dc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class KSTypeImpl private constructor(internal val type: KaType) : KSType {
}

override val declaration: KSDeclaration by lazy {
(type as? KaFunctionType)?.abbreviatedSymbol()?.toKSDeclaration() ?: type.toDeclaration()
(type as? KaFunctionType)?.abbreviatedSymbol()?.toKSDeclaration()
?: type.abbreviation?.toDeclaration() ?: type.toDeclaration()
}

override val nullability: Nullability by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ class KSPAATest : AbstractKSPAATest() {
@TestMetadata("typeAlias.kt")
@Test
fun testTypeAlias() {
runTest("../test-utils/testData/api/typeAlias.kt")
runTest("../kotlin-analysis-api/testData/typeAlias.kt")
}

@TestMetadata("typeAliasComparison.kt")
Expand Down
67 changes: 67 additions & 0 deletions kotlin-analysis-api/testData/typeAlias.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2020 Google LLC
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// WITH_RUNTIME
// TEST PROCESSOR: TypeAliasProcessor
// EXPECTED:
// a : A = String
// b : B = String
// c : CC = A = String
// d : String
// listOfInt : ListOfInt = List<Int>
// listOfInt_B : ListOfInt_B = ListOfInt = List<Int>
// listOfInt_C : ListOfInt_C = ListOfInt_B = ListOfInt = List<Int>
// myList : MyList<Long> = List<T>
// myList_B : List<Number>
// myList_String : MyList_String = MyList<String> = List<T>
// myList_b_String : MyList_B_String = MyList_B<String> = MyList<R> = List<T>
// myListOfAlias : MyListOfAlias = List<@JvmSuppressWildcards A>
// myListOfAliasInLib : MyListOfAliasInLib = List<@JvmSuppressWildcards AInLib>
// END

// MODULE: module1
// FILE: KotlinLib.kt
typealias AInLib = String
typealias MyListOfAliasInLib = List<@JvmSuppressWildcards AInLib>

// MODULE: main(module1)
// FILE: KotlinSrc.kt
typealias A = String
typealias B = String
typealias CC = A
typealias ListOfInt = List<Int>
typealias ListOfInt_B = ListOfInt
typealias ListOfInt_C = ListOfInt_B
typealias MyList<T> = List<T>
typealias MyList_B<R> = MyList<R>
typealias MyList_String = MyList<String>
typealias MyList_B_String = MyList_B<String>
typealias MyListOfAlias = List<@JvmSuppressWildcards A>

val a: A = ""
val b: B = ""
val c: CC = ""
val d: String = ""
val listOfInt: ListOfInt = TODO()
val listOfInt_B: ListOfInt_B = TODO()
val listOfInt_C: ListOfInt_C = TODO()
val myList: MyList<Long> = TODO()
val myList_B: List<Number> = TODO()
val myList_String: MyList_String = TODO()
val myList_b_String: MyList_B_String = TODO()
val myListOfAlias: MyListOfAlias = TODO()
val myListOfAliasInLib: MyListOfAliasInLib = TODO()
3 changes: 2 additions & 1 deletion test-utils/testData/api/typeAlias.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// myList_B : List<Number>
// myList_String : MyList_String = MyList<String> = List<T>
// myList_b_String : MyList_B_String = MyList_B<String> = MyList<R> = List<T>
// myListOfAlias : MyListOfAlias = List<@JvmSuppressWildcards A>
// myListOfAlias : MyListOfAlias = List<A>
// myListOfAliasInLib : MyListOfAliasInLib = List<@JvmSuppressWildcards AInLib>
// END

Expand Down Expand Up @@ -63,5 +63,6 @@ val myList: MyList<Long> = TODO()
val myList_B: List<Number> = TODO()
val myList_String: MyList_String = TODO()
val myList_b_String: MyList_B_String = TODO()
// FIXME: type annotation is missing
val myListOfAlias: MyListOfAlias = TODO()
val myListOfAliasInLib: MyListOfAliasInLib = TODO()

0 comments on commit 1f7b4dc

Please sign in to comment.