Skip to content

Commit d3e0839

Browse files
committed
Add test for explicit backing fields
See KEEP 430
1 parent 2aa2620 commit d3e0839

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/AAConfiguredUnitTestSuite.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class AAConfiguredUnitTestSuite : KSPUnitTestSuite(experimentalPsiResolution = f
2828
runFailingTest("$AA_PATH/getSymbolsWithAnnotation/negative/allUseSiteTargetAppliedToAnnotationList.kt")
2929
}
3030

31+
@TestMetadata("explicitBackFields.kt")
32+
@Test
33+
override fun testExplicitBackingFields() {
34+
runTest("$AA_PATH/getSymbolsWithAnnotation/explicitBackingFields.kt")
35+
}
36+
3137
@TestMetadata("javaSubtypeOfKotlinInterface.kt")
3238
@Test
3339
override fun testJavaSubtypeOfKotlinInterface() {

kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/KSPUnitTestSuite.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ abstract class KSPUnitTestSuite(
307307
runTest("$AA_PATH/errorTypes.kt")
308308
}
309309

310+
@Bug(
311+
"https://github.com/google/ksp/issues/2873",
312+
BugState.OPEN,
313+
"Explicit backing fields added in Kotlin 2.4.0"
314+
)
315+
abstract fun testExplicitBackingFields()
316+
310317
@TestMetadata("fieldAndPropertyUseSiteTargetOnConstructorParameters.kt")
311318
@Test
312319
@Bug("https://github.com/google/ksp/issues/2913", BugState.FIXED)

kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/test/PsiConfiguredUnitTestSuite.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class PsiConfiguredUnitTestSuite : KSPUnitTestSuite(experimentalPsiResolution =
2828
runTest("$AA_PATH/getSymbolsWithAnnotation/negative/allUseSiteTargetAppliedToAnnotationList.kt")
2929
}
3030

31+
@TestMetadata("explicitBackFields.kt")
32+
@Test
33+
override fun testExplicitBackingFields() {
34+
runThrowingTest("$AA_PATH/getSymbolsWithAnnotation/explicitBackingFields.kt")
35+
}
36+
3137
@TestMetadata("javaSubtypeOfKotlinInterface.kt")
3238
@Test
3339
override fun testJavaSubtypeOfKotlinInterface() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
* Copyright 2010-2026 JetBrains s.r.o. and Kotlin Programming Language contributors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// TEST PROCESSOR: GetSymbolsWithAnnotationProcessor
19+
// PROCESSOR INPUT: Anno
20+
// EXPECTED:
21+
// Anno: MyClass.annotatedProperty
22+
// Anno: MyClass.annotatedPropertyAndFieldViaUseSiteTargets
23+
// Anno: MyClass.annotatedPropertyWithFieldTarget
24+
// Anno: MyClass.propertyWhereFieldIsDirectlyAnnotated
25+
// Anno: MyClass.propertyWithAllTarget
26+
// Anno: MyClass.propertyWithAllTarget.propertyWithAllTarget.getter()
27+
// END
28+
29+
// FILE: Main.kt
30+
31+
annotation class Anno
32+
33+
class MyClass {
34+
@Anno // Should just pick the property
35+
val annotatedProperty: List<String>
36+
field = MutableList<String>
37+
38+
val propertyWhereFieldIsDirectlyAnnotated: List<String>
39+
@Anno field = MutableList<String>
40+
41+
@field:Anno
42+
val annotatedPropertyWithFieldTarget: List<String>
43+
field = MutableList<String>
44+
45+
@field:Anno
46+
@property:Anno
47+
val annotatedPropertyAndFieldViaUseSiteTargets: List<String>
48+
field = MutableList<String>
49+
50+
@all:Anno
51+
val propertyWithAllTarget: List<Int>
52+
field = MutableList<Int>
53+
}

0 commit comments

Comments
 (0)